5

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.

1
  • i don't know yii, but I've implemented something like this before. If i had made it i would have the rules keys and values switched.... Apr 26, 2013 at 4:09

3 Answers 3

2

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.

2
  • Accepting this as the answer since yours is the most thorough, although, for the record, I have since moved on from this project and don't have the site setup to test this solution. Sep 13, 2013 at 2:27
  • got know luck any suggestions?? Jan 15, 2014 at 18:20
1

What happens if you delete these lines!

enter code here
    # otherwise forward it to index.php
    RewriteRule . index.php
1
  • Still, the same problem. I moved onto a different project without ever actually getting this working in Yii! Kind of frustrating, but I'll let you know if I face the same problem the next time I am working on another Yii project. Jul 10, 2013 at 3:26
1

if you add this code see if it works

'<action:(login|logout|register|contact)>' => 'site/<action>',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.