Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii :: Issue Using Showscriptname = False And Url Manager

I am currently having an issue using the URL manager and/or the apache mod_rewrite or maybe something else entirely.

With showScriptName set to false, navigating to addresses such as domain.com/login, domain.com/logout, domain.com/site/login are all behaving the same way. It simply shows the main site/index, as if I were to navigate to domain.com/eeofjew9j8jfdedfmewf (jibberish).

Maybe it's an issue with my Yii settings? Here are those (sorry for the sloppiness):

'components'=>array(
   'urlManager'=>array(
      'urlFormat'=>'path',
      'showScriptName'=>false,
      'rules'=>array(
          '<controller:\w+>/<id:\d+>'=>'<controller>/view',
          '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
          '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
          'login'=>'site/login',
          'logout'=>'site/logout',
          'register'=>'users/register'
      ),
  ,...

Here is how I have my .htaccess setup in the www root:

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

I am using a VPS server, so I have root access to make any changes needed to apache. I've checked my phpinfo and mod_rewrite is running and enabled. In my apache config, I have for my www directory:

AllowOverride All
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all

I've been scratching my head on this issue through 3 different hosts (godaddy, dreamhost, and lithiumhosting) so I'm assuming it's an issue on my end with this. Now that I have a VPS though, I'm hoping I can finally figure out my issue and solve it.

like image 783
Owen McAlack Avatar asked Oct 05 '22 07:10

Owen McAlack


1 Answers

First verify that the server is parsing the .htaccess file. This is simply done by placing random text in the .htaccess file such as

CREATE AN ERROR

If this gives you a server error then the file is being parsed. You may have to move the .htaccess file up a directory to get this to work.

After this is working check to make sure the rewrite module in Apache is on. First check phpinfo and look for the running module. If not you may have to delete the comment (#) character in front of the module.

After the module shows up in phpinfo then see if you can do a basic rewrite to make sure that there are not problems with Apache.

RewriteEngine on
RewriteRule ^ http://google.com/? [L,R]

If that is not working try adding the

Options +SymLinksIfOwnerMatch

to the file

Once you have Apache doing it's part now it is up to yii. This code:

RewriteEngine On
RewriteBase /mybasedirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

adds the rewrite base option which may be necessary if you do not have the files in the document root such as htdocs

finally if that does not solve the problem then limit your rule to a simple rule such as

      'contact'=>'site/contact',

and see if at least redirects to where you think it should. Of course you may have to check the basic rules of .htaccess again to make sure that overide is allowed and there isn't an errant .htaccess in a subdirectory. I hope that helps. I finally got mine working.

like image 100
Kurt Avatar answered Oct 13 '22 12:10

Kurt