PDA

View Full Version : Mod rewrite, moving directories (consolidating rules)


Coastal Web
10-16-2009, 05:23 PM
Hi everyone, l'm in the process of cleaning up one of our servers, and in doing so l'm consolidating several root level directories into sub directories; and in setting up the htaccess file for the 301 redirects l've come up with a few questions.

Forst off here are a few redirects that are being moved from root, to /pages>:
new_carissa_poster -> /pages/new_carissa_poster
medical_guide -> /pages/medical_guide
elections -> /pages/elections

And here is the htaccess code l'm using for the redirect (they work fine):
RewriteRule ^new_carissa_poster(.*) "/pages/new_carissa_poster$1" [R=301,L]
RewriteRule ^medical_guide(.*) "/pages/medical_guide$1" [R=301,L]
RewriteRule ^elections(.*) "/pages/elections$1" [R=301,L]


My question is, is there a way to consolidate these into one rule, something like:

RewriteRule ^(new_carissa_poster|medical_guide|elections)(.*) "/page/$1/$2" [R=301,L]

My problem is the "/pages/$1/$2" bit, l'm not sure what to do here. Any help would be great!


Also l've gotten sub directories that are being moved deeper, for instance:

/pages/bay_appliance -> /pages/expired/bay_appliance
/pages/coos_bay_toyota -> /pages/expired/coos_bay_toyota

So my rewrite rules are:
RewriteRule ^pages/bay_appliance(.*) "/pages/expired/bay_appliance$1" [R=301,L]
RewriteRule ^pages/coos_bay_toyota(.*) "/pages/expired/coos_bay_toyota$1" [R=301,L]

I'd like to do the same thing as above (consolidate the rule into one single rule) but l'm hitting a wall on doing so and can't figure it out. If this is possible please let me know guys!

Thanks!

ess
10-19-2009, 04:25 PM
haven't tested those, but might be a good starting point

first, you should have all you of working re-directs at the top. in order words, write

Options +FollowSymLinks
Options +SymlinksIfOwnerMatch

RewriteEngine On
RewriteBase /

RedirectMatch ^pages/123/(.*)$ /456/$1

Add the following rule after the above and before any error redirection

RedirectMatch ^pages/[bay_appliance|coos_bay_toyota](.*)$ pages/expired/$1/$2 [R=301,L]

thanks

Coastal Web
10-19-2009, 05:39 PM
Hi ess,

Thanks for your response. I've tried the following:

RedirectMatch ^pages/[bay_appliance|coos_bay_toyota|cvh|inland_point|macks_sawshop|mckays|morey_ranch|northbend_lanes|schr oeder_and_sons|south_coast_beauty_supply](.*)$ pages/splash_pages/$1/$2 [R=301,L]

But it doesn't seem to redirect any of the specified directories, any ideas?