views:

1055

answers:

1

Ok. So I'm building this site which is accessible through two different domains. So I can't use RewriteBase in my .htaccess. The rules (below) I use to work around this problem seem to work fine. However, when I use the below .htaccess settings on my local box with clean URLS (WAMP) it all works fine but the moment I use this on the live server (shared hosting LAMP) every page I navigate to displays the home page (the one under index I guess) even though the URL in the browser is clearly being updated.

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/domain1.com/(.*)$
  RewriteRule ^(.*)$ /domain1.com/index.php?q=$1 [L,QSA]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} ^/domain2.com/(.*)$
  RewriteRule ^(.*)$ /domain2.com/index.php?q=$1 [L,QSA]
</IfModule>

Any help or ideas are very much appreciated.

  • Luke
+2  A: 

Probably the best thing to do is to reproduce the problem on your local box and turn up RewriteLogLevel so you can see what's going on. (Since you usually can't change the log level on shared hosting)

You may be able to "simulate" the problem by doing a directory rewrite in your Apache main configuration. (The shared hosting obviously does its own rewriting before it gets to the .htaccess!) If you can't reproduce the problem, you may have to start trial-and-error debugging on the remote server. This is ugly but if it's your only option:

Use the R (redirect) flag in substitutions to send any rewritten URL back to your browser. Use TELNET (or an appropriate browser add-on) to inspect the HTTP responses.

Don't forget to escape dots in regexes!

As a side note, the RewriteRule pattern is matched before the RewriteConds above it. This kind of setup is probably better for performance:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/domain1\.com/(.*)$ /domain1.com/index.php?q=$1 [L,QSA]
#                     ^ should be escaped

Note that I haven't tested this.

Artelius