Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite not working for index.php

.htaccess Rewrite works for everything except the index.php file

         

stratagem

6:48 am on Jul 6, 2005 (gmt 0)

10+ Year Member



Does anyone know why a rewrite rule would not work for the index.php file? I use the .htaccess to redirect a second domain to a subdirectory of the first domain. Here is a copy:

RewriteEngine On
RewriteCond %{HTTP_HOST} second-domain.com$ [NC]
RewriteCond %{REQUEST_URI}!^/second-domain/.*$
RewriteRule (.*) /second-domain/$1

When I go to www.second-domain.com it pulls up the page correctly (index.php), but if I go to www.second-domain.com/index.php it does not. I tested the redirect with other files in the second-domain directory and it works fine. Only index.php fails.

Any thoughts? Thanx.

jdMorgan

5:36 pm on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's nothing in your code that looks incorrect, although a few tweaks might improve performance slightly:

RewriteEngine On
RewriteCond %{HTTP_HOST} second-domain\.com [NC]
RewriteCond %{REQUEST_URI} !^/second-domain/
RewriteRule (.*) /second-domain/$1 [L]

You might want to check for other rules that may be interfering, such as in httpd.conf.

Also, being very specific, if *only* your index.php file is failing with mod_rewrite, and you *do* have other php files in the same directory that work, then you've got some very specific problem and it should be easy to find. At the other end of the scale, if *all* of your php files fail, and you're running on Apache 1.x, then it's likely that you have an error in your LoadModule list order in httpd.conf, and php is running before mod_rewrite is invoked. If this is the case, then PHP must be loaded *before* mod_rewrite in order to execute *after* mod_rewrite. The execution priority is the reverse of the loadmodule order on Apache 1.x

Jim

stratagem

7:10 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



Thanks Jim,

I uploaded phpinfo.php and sure enough it looks like there is a problem with the loadModules order. Unfortunately this domain is hosted on servers other than my own so I don't have control of the httpd.conf.

I'll contact them and see if they can resolve the problem. Let's hope so! Thanks for the suggestions for the improvements to my .htaccess file as well.

Thanks for the great help,

Robert