Forum Moderators: phranque
I have an old site where I want to redirect everything except /x/ to another domain - and by everything I mean including /x/somefile.htm, but not /x/index.htm.
In other words, the only URI's that don't get redirected are the ones that are exactly /x, /x/, and /x/index.htm. Each of these should display the contents of /x/index.htm, everything else gets redirected.
The document index is set to index.htm, and I'm making the changes in httpd.conf. In addition, I normally have a "ErrorDocument 404 /index.htm" line for this domain (although the example below doesn't even work without it).
So, one of many attempts is:
RewriteCond %{REQUEST_URI}!/x$ [NC]
RewriteCond %{REQUEST_URI}!/x/$ [NC]
RewriteCond %{REQUEST_URI}!/x/index.htm$ [NC]
RewriteRule (.*) http:/*www.anotherdomain.com [L]
However, only the /x/index.htm gets displayed, the other forms get redirected. (I've tried it with front-anchors etc, this is just the simplest case, and it's intentionally a 302 redirect).
Can anybody point out what silly mistake I'm making? Thanks!
I'd check to make sure that your don't have a higher-level .htaccess/httpd.conf setting that is overriding this, and that all your preamble code, such as RewriteEngine on, Options, etc., are set up correctly.
Jim
The problem is probably outside the scope of that code.
Thanks for that suggestion - I looked further and then it clicked...
The DirectoryIndex I had for that domain was "DirectoryIndex index.php index.htm ", only index.htm exists. When I switched the order of the names in DirectoryIndex (i.e. .htm first) it worked.
So /x/ was looking for each directory index in turn. Even though index.php doesn't exist, just looking for it was enough to trigger the rewrite so that it'd never get to the index.htm. Putting them in the reverse order means that index.htm is tried first, which does match the exclude.
Thanks again.