[Solved] Url For Module Not Working In Localhost (With Pretty Urls)

I’ve been banging my head against a wall with this.

I have a project that works perfectly on my Linux server. I want to work on it in localhost and update it with github, so I downloaded it. I work on a Windows 7 Professional (64 bits) machine, with IIS 7.

Problem is, the application doesn’t work correctly with the pretty URLs (path URL format) in localhost. I installed XAMPP and it’s the same problem both in Apache and in IIS.

My application will work just fine when I open it like: "localhost/myapp"

I can navigate any controller just fine, HOWEVER, once I use any of its modules, it craps out on me and gives me a 403 Unauthorized error. For example “localhost/myapp/<mymodule/” won’t work. It seems as if the application thinks it’s a controller and not a module or something, so the permissions of the user don’t work.

It works just fine on the server, so I’m running in circles trying to figure out WTF is wrong. I have a bit of a workaround, but not a fix. I add an access rule in my Controller class from where every other controller extends from and allow every user to access everything




array(

    'allow',

    'users'=>array('*')

)



but if I ever need to do some security tests, I’m screwed.

To me, it seems like some URL rewrite problem, but it’s not really clear to me why it happens if it’s working with everything else BUT with the modules.

This is my URL manager component in my main.php configuration file.




                'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

			'showScriptName'=>false //Para eliminar index.php de la URL

		),

My IIS web.config:




<?xml version="1.0" encoding="UTF-8"?>

<configuration>

<system.webServer>

 

<directoryBrowse enabled="false" />

 

    <rewrite>

        <rules>

        <rule name="Hide Yii Index" stopProcessing="true">

            <match url="." ignoreCase="false" />

            <conditions>

            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />

            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />

            </conditions>

                <action type="Rewrite" url="index.php" appendQueryString="true" />

        </rule> 

        </rules>

    </rewrite>

 

</system.webServer> 

</configuration>



My Apache .htaccess




Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

RewriteBase /myAppName/


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



I just got the last two from the Internet, since I don’t really know much about setting up URL rules.

I solved the problem. It was some weird situation with the accessRules.

I just had to add the module name in the controller, like:




array(

    'allow',

    'controllers'=>'myModule/myController',

    'users'=>array('*')

)



Using only the name of the controller wouldn’t work.