problem with url rewriting

Hi, I’m new to Yii and Iam facing a major headache to setup the rewriting procedure.

I did an intensive search to the problem that Iam facing and I did all the configurations needed to activate the rewrite but without any luck, so I choose to write it hopefully someone will help me.

The problem is that all the links I request only the index view page is displayed.

ex: (not working)

xxxx://localhost/MyApplication/site/contact

xxxx://localhost/MyApplication/site/login

etc…

But when I insert the index.php before the controllerID then the proper view is displayed

ex: (working)

xxxx://localhost/MyApplication/index.php/site/contact

xxxx://localhost/MyApplication/index.php/site/login

etc…

Iam using wamp and my configuration are:

.htaccess (configuration)



Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


# 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

main.php (config file)



		

'urlManager' => array(

   'urlFormat'=>'path',

   'showScriptName'=>false,

   'caseSensitive'=>false,

),



I hope someone would direct me how to solve my problem and thanks in advance.

When trying to visit a URL without /index.php/, insert a var_dump($_SERVER);exit; in your site controller’s index action, then view source, and copy/paste the array output here please.




array(34) {

  ["REDIRECT_STATUS"]=>

  string(3) "200"

  ["HTTP_HOST"]=>

  string(9) "localhost"

  ["HTTP_USER_AGENT"]=>

  string(93) "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 Glue/4.5"

  ["HTTP_ACCEPT"]=>

  string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"

  ["HTTP_ACCEPT_LANGUAGE"]=>

  string(14) "en-us,en;q=0.5"

  ["HTTP_ACCEPT_ENCODING"]=>

  string(12) "gzip,deflate"

  ["HTTP_ACCEPT_CHARSET"]=>

  string(30) "ISO-8859-1,utf-8;q=0.7,*;q=0.7"

  ["HTTP_KEEP_ALIVE"]=>

  string(3) "115"

  ["HTTP_CONNECTION"]=>

  string(10) "keep-alive"

  ["HTTP_COOKIE"]=>

  string(36) "PHPSESSID=tn027svmb2tuau633mepjfb673"

  ["PATH"]=>

  string(321) "C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\Apache Software Foundation\Apache2.2\bin;C:\PHP;;C:\Program Files\MKVtoolnix;C:\wamp\bin\php\php5.3.0;C:\wamp\www\_Yii\framework"

  ["SystemRoot"]=>

  string(10) "C:\WINDOWS"

  ["COMSPEC"]=>

  string(27) "C:\WINDOWS\system32\cmd.exe"

  ["PATHEXT"]=>

  string(48) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"

  ["WINDIR"]=>

  string(10) "C:\WINDOWS"

  ["SERVER_SIGNATURE"]=>

  string(0) ""

  ["SERVER_SOFTWARE"]=>

  string(31) "Apache/2.2.11 (Win32) PHP/5.3.0"

  ["SERVER_NAME"]=>

  string(9) "localhost"

  ["SERVER_ADDR"]=>

  string(9) "127.0.0.1"

  ["SERVER_PORT"]=>

  string(2) "80"

  ["REMOTE_ADDR"]=>

  string(9) "127.0.0.1"

  ["DOCUMENT_ROOT"]=>

  string(12) "C:/wamp/www/"

  ["SERVER_ADMIN"]=>

  string(15) "admin@localhost"

  ["SCRIPT_FILENAME"]=>

  string(40) "C:/wamp/www/_eHealthAll (beta)/index.php"

  ["REMOTE_PORT"]=>

  string(4) "3591"

  ["REDIRECT_URL"]=>

  string(40) "/_eHealthAll (beta)/site/page/view/about"

  ["GATEWAY_INTERFACE"]=>

  string(7) "CGI/1.1"

  ["SERVER_PROTOCOL"]=>

  string(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> "HTTP/1.1"

  ["REQUEST_METHOD"]=>

  string(3) "GET"

  ["QUERY_STRING"]=>

  string(0) ""

  ["REQUEST_URI"]=>

  string(42) "/_eHealthAll%20(beta)/site/page/view/about"

  ["SCRIPT_NAME"]=>

  string(29) "/_eHealthAll (beta)/index.php"

  ["PHP_SELF"]=>

  string(29) "/_eHealthAll (beta)/index.php"

  ["REQUEST_TIME"]=>

  int(1267129599)

}



Do you have "AllowOverride None" in your Apache config?

/Tommy

Try adding this to your htaccess below ‘RewriteEngine on’:

RewriteBase /_eHealthAll (beta)/

You may need to put the path in quotes, I’m not sure since I don’t use spaces in folder names.

No




<Directory />

    Options FollowSymLinks

    AllowOverride all

    Order deny,allow

    Deny from all

</Directory>


<Directory "c:/wamp/www/">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks


    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride All


    #

    # Controls who can get stuff from this server.

    #


#   onlineoffline tag - don't remove

    Order Deny,Allow

    Deny from all

    Allow from 127.0.0.1


</Directory>



Thanks u so much, I think I found the problem IT IS THE WHITE SPACE.

I should never use it in the first place but I like to flag my projects as beta in development :D .

so thanks u all guys for the fast response.

The best approach is to typically replace any spaces with hyphens or underscores, regardless of if it’s for the web or not, because you never know when a file may be shared/uploaded somewhere and cause issues because of a space :slight_smile:

RewriteBase /

localhsot/yii/demos/blog

You must Changes RewriteBase /yii/demos/blog