views:

44

answers:

1

Hi,

I am using mod_rewrite to create SEO URLs. Basically the thing works in the following way: all requests are caught by .htaccess and redirected to a php script (let's say transform.php). transform.php parses SEO URL and transforms it into a normal URL, then includes index.php, then catches application's (index.php's) output and uses RegEx to convert all normal URLs to SEO URLs. So the vital step is to make all request go through transform.php. My .htaccess is rather long however I managed to limit it to the following lines.

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on

    RewriteRule ^index\.php?(.*)$ ./transform.php?p=$1&%{QUERY_STRING} [L]

</IfModule>

The problem happens with the initial (root) URL: http://mysite.com/. When I type http://mysite.com/ and site is located on my local comp, everything works fine. http://mysite.com/ is caught by .htaccess and sent to transform.php for further processing. However on another server this line doesn't work (let's say for http://mysite-other-server.com/). This .htaccess line simply doesn't catch the request. Everything works fine for http://mysite-other-server.com/index.php though.

Moreover I have several sites on this second server and some of them work while some of them don't. It's like for some of them the URL is first resolved to http://mysite-other-server.com/index.php and then handled by .htaccess while for others the URL is not resolved and .htaccess deals with http://mysite-other-server.com/

I am very confused and tried googling without any luck. Any help is highly appreciated.

+1  A: 

I assume that Apache is configured not to accept .htacces files.

You must enable it from the httpd configuration with the AllowOverride setting.

http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride

Another possibility is that the production server hasn't loaded mod_rewrite, check the LoadModule directives for that.

Johnco
Hi and thanks for your reply!The server definitely accepts .htaccess files because http://mysite-other-server.com/index.php works as expected. The same goes for mod_rewrite. However for some reason http://mysite-other-server.com/ doesn't produce the same result. It still goes into .htaccess file howeverRewriteRule ^index\.php?(.*)$ ....doesn't have any affect. While on other sites on this same serverRewriteRule ^index\.php?(.*)$ .... works fine for http://mysite-other-server.com/
Eugene
So to sort things out:http://mysite-other-server.com/andhttp://mysite-other-server123.com/are on the same server. The same .htaccess file and transform.php is used for both. Both http://mysite-other-server123.com/ and http://mysite-other-server123.com/index.php are matched by that regexp and go into transform.phpBut only http://mysite-other-server.com/index.php is matched while http://mysite-other-server.com/ is not.
Eugene
Beware the AllowOverride directive can be set to a specific VirtualHost, allowing a single Apache to have a domain working and the otherone not.
Johnco
Thanks for the tip. The cPanel "virtualHost" templates have changed for some reason and all newly created sites were getting different virtualHost entries. Judging from the differences between old and new sites, the config that affects this is UseCanonicalName OffThe sites that don't have this config, have the issue while the sites with this config function well. Anyway thank you very much! Your tip was very important and made me have a look into the right direction!
Eugene