6

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!

guivalerio
  • 81
  • 1
  • 6
  • You might need YII tell where the basefolder is and which baseurl it represents, but I'm no YII expert. – hakre Mar 16 '12 at 00:48
  • Have you tried adding `RewriteLog` and `RewriteLogLevel` to see what is going on? http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog – James Holwell Mar 16 '12 at 00:49
  • @hakre, the Yii application basePath (if that's what you meant) is set to `Yii::getPathOfAlias('site.frontend')`, which means public_html/mysite/frontend/. I have also tried adding RewriteBase to `/mysite` and `/mysite/frontend/www`, but nothing changed. – guivalerio Mar 16 '12 at 09:16
  • @JamesHolwell I haven't tried that but I'll give it a go later on today when I'm back in my machine. Thanks! :) – guivalerio Mar 16 '12 at 09:17

4 Answers4

4

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.

Community
  • 1
  • 1
Evan
  • 141
  • 4
0

You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.

After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).

That should be all you need to do, but if you need more details, I describe the approach fully here:

http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory

0

I also didn't update the .htaccess file, easier to modify the httpd.conf virtual host for the subdomain and change the DocumentRoot to point to your yii folder.

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
0

You didn't mention if you configured Yii's Url Manager for clean URLs. You need to, otherwise Yii expects the "route" to appear as a GET param named "r". If you didn't, consult this section of the definitive guide

Boaz Rymland
  • 1,459
  • 11
  • 29
  • Yes I am using clean URLs. `urlFormat'=>'path'` and `'showScriptName'=>false`. So everything looks ok on that side. – guivalerio Mar 16 '12 at 09:49