Forum Moderators: phranque

Message Too Old, No Replies

Can mod rewrite run in a subdir, below the root level?

Redirect works, RewriteEngine does not

         

MichaelBluejay

8:25 am on Jan 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was excited to discover that I can create an <.htaccess> in a subdirectory and put in Redirect 301's for requests made to that directory, so that I don't have to have a huge <.htaccess> file at the root level, which might slow down the server a little.

But I've had no luck in getting mod rewrite to work in a subdirectory. I don't get any error message, it just seems to ignore the code I have in the <.htaccess> file. Here's an example of my code, which works fine when it's in the <.htaccess> in the root directory:

RewriteEngine on
RewriteRule ^subdir/filename(.*)$ [domain\.com...] [R=301,L]

Is there a way to get this to execute in an <.htaccess> file inside a subdirectory?

jdMorgan

5:24 pm on Jan 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The local URL-path "seen" by RewriteRule is local to the subdirectory in which the code resides. In other words, if your code is in /"subdir", then the following code won't work:

RewriteEngine on
RewriteRule ^[b]subdir[/b]/filename(.*)$ http://domain\.com/subdir/numbered/filename$1 [R=301,L]

Actually, it would work, but only if the requested URL was example.com/subdir/subdir.

So, I suspect the answer to your problem is to adjust the URL pattern for its local context, and use:


RewriteEngine on
RewriteRule ^filename(.*)$ http://domain\.com/subdir/numbered/filename$1 [R=301,L]

for the RewriteRules in .htaccess in your "/subdir" directory which apply to the resources in your "/subdir" directory.

Jim

[edited by: jdMorgan at 6:06 pm (utc) on Jan. 1, 2005]

MichaelBluejay

6:03 pm on Jan 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Damn you're good. That fixed it right up. Thanks!

I should have thought of that, don't know why I didn't.