Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess for site in sub-directory using Yii framework

I have looked at several examples of htaccess configs for websites within sub-directories, and tried most of them without 100% success.

My setup is:

  • using Yii framework
  • htaccess at public_html/.htaccess
  • site located inside public_html/mysite directory
  • index handling all requests located at public_html/mysite/frontend/www/index.php

The status of the URLs:

  • www.mysite.com works fine [ok]
  • www.mysite.com/controller/action shows me the homepage [wrong]
  • www.mysite.com/mysite/frontend/www/controller/action works fine [wrong, the item above should work instead]

My .htaccess at the moment looks like this:

AddHandler application/x-httpd-php53s .php .html

Options +SymLinksIfOwnerMatch
IndexIgnore */*

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www

RewriteRule ^(.*)?$ /mysite/frontend/www/index.php [L]

I have tried everything, but I have no idea why www.mysite.com/controller/action won't work :(

Any help would be really appreciated! Thanks!

like image 616
guivalerio Avatar asked Mar 16 '12 00:03

guivalerio


1 Answers

I found the answer to this similar question to be helpful. Here is how my rewrite rules ended up:

#Forward all non-existent files/directories to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]

This takes all non-existent files/folders and sends them to the yii script with initial url appended. QSA appends any query string that may be present in the initial url.

like image 184
Evan Avatar answered Nov 07 '22 08:11

Evan