This is a discussion on rewrite woes within the Apache Web Server forums, part of the Web Server and Related Forums category; I have a site (call it thesite.com) that I want always accessed as www.thesite.com, so I have ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a site (call it thesite.com) that I want always accessed as
www.thesite.com, so I have been using the following rule: RewriteCond %{HTTP_HOST} ^thesite\.com [nc] RewriteRule (.*) http://www.thesite.com/$1 [R=301,L] So far so good. I also want to be able to use search engine friendly (SEF) urls with the CMS on the site, so I just added. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php BUT... I also have test installations of the CMS in subdirectories (e.g. www.thesite.com/turnip, www.thesite.com/parsnip, ...) Now since adding the SEF stuff, when I try to click onto a link in turnip, it takes me to the main site in the root directory. So I tried adding a new .htaccess file in the turnip directory thus: RewriteCond %{HTTP_HOST} ^thesite\.com/turnip [nc] RewriteRule (.*) http://www.thesite.com/turnip/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php Which fixes the problem of being sent back to the root site, but it is also losing the www off of the front of the urls if they are typed in the browser. So when I enter www.thesite.com/turnip, is is ending up with thesite.com/turnip in the browser. Can anyone point me to what I need to do to: 1) enable my SEF urls 2) ensure all addresses in the browser have www. at the front 3) be able to access all the test installations in their subdirectories as well as the main site in the root I hope this is clear. TIA Regards Paul Lautman |
|
|||
|
Robert Ionescu wrote:
> Paul Lautman wrote: >> RewriteCond %{HTTP_HOST} ^thesite\.com/turnip [nc] > > The HTTP_HOST does not contain parts of the URL-path. > > RewriteCond %{HTTP_HOST} ^thesite\.com I didn't mention that I had only tried adding the /turnip in the RewriteCond because it was not working without it. But I discovered that the RewriteEngine On line was missing from the turnip ..htaccess. Here is what I have: In root: RewriteEngine On RewriteCond %{HTTP_HOST} ^thesite\.com [nc] RewriteRule (.*) http://www.thesite.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php In /turnip: RewriteEngine On RewriteCond %{HTTP_HOST} ^thesite\.com RewriteRule (.*) http://www.thesite.com/turnip/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php It is working, but is there any way over this without having to have a dedicated .htaccess file in each subdirectory? TIA Regards Paul |
|
|||
|
Paul Lautman wrote:
> It is working, but is there any way over this without having to have a > dedicated .htaccess file in each subdirectory? It depends upon what you'd like to achieve. With your /turnip/.htaccess, you're rewriting such requests to /turnip/index.php and not to /index.php -- Robert |