Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Rewrite excluding one directory (except contents)

How to exclude just a directory index?

     
8:01 am on Jan 8, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 1, 2003
posts:392
votes: 0


Simple rewrite question - but this one's got me going round in circles...

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]

To me, that should say that if the request is NOT a request for the index file of the "x" directory, in any of the three ways it can be written, then redirect, otherwise leave alone.

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!

8:47 pm on Jan 8, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


No mistakes that I can see - your code looks fine. The problem is probably outside the scope of that code.

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

11:17 pm on Jan 8, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 1, 2003
posts:392
votes: 0


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.