Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule

for directories

         

rover

8:22 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



Hi,

I just made a big mistake on our site, and am urgently trying to solve it with a rewrite rule that would take a url with the structure:

[example.com...]

and actually return the page

[example.com...]

Basically, no matter what the directory1 and directory2 names are, and what comes after them, I always need them replaced by the single main-directory.

I can't seem to get anything that will work. If anyone has a quick fix on what would work it would be greatly appreciated.

jdMorgan

9:27 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your code so we can discuss it.

Jim

rover

10:10 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



I've been trying a lot of different ways. My latest is the following with an .htaccess file in 'directory1'

RewriteEngine on
RewriteRule ^(.*)/(.*) main-directory/$2 [L]

(directory1 is always the same directory1 name, but directory2 is a variety of different directory names):

jdMorgan

1:55 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, how about this in /directory1/.htaccess:

RewriteEngine on
RewriteRule ([^/]*)$ /main-directory/$1 [L]

This will take everything after the last slash (if any) in the URL-path, and append it to the main-directory path. The missing start anchor is very intentional.

You didn't say if mod_rewrite is working at all; If not, then you may need to add

 Options +FollowSymLinks 

ahead of the code above (This depends on your server config, and may not be needed).

Jim