Forum Moderators: phranque

Message Too Old, No Replies

URL Redirecting

         

krish1

2:08 pm on Aug 8, 2012 (gmt 0)

10+ Year Member



Hi Everyone

I have a requirement where i need to redirect the old URLs to the new ones(the site structure of the site is being changed)

I have nearly 400 URLs, for most of them which have some patterns i used 301 Redirectmatch and 301 redirects,by putting them directly into the config file(some 80 -90 rules).

But there are still some 100 URLs which doesn't have any patterns
Can anyone suggest me, what is the best way which i can go for?

g1smd

6:29 pm on Aug 8, 2012 (gmt 0)

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



Make sure that all of your redirects use the same Apache module. Preferably use mod_rewrite for all of them.

You might just need to list them all individually.

lucy24

10:38 pm on Aug 8, 2012 (gmt 0)

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



It depends on exactly how many patternless redirects you have. If there are not too many, you can write a separate rule for each one. The alternative is to change all your existing mod_alias Redirects to mod_rewrite with the Redirect flag [R=301]. And then the leftover pages get rewritten (not redirected) to a php page which looks up the new URL and issues a Redirect.

So it depends on whether you would rather write 100 rules or learn php ;)

All of this is assuming the new site structure gives you URLs which look better than the old ones. If the changed site structure would result in longer or more complicated URLs, you might prefer to keep the old URL and use a Rewrite (no redirect) to serve content from the new location.

krish1

8:55 am on Aug 9, 2012 (gmt 0)

10+ Year Member



Thanks for the Replies,

Can Someone say me, what happens if i use both RedirectMatch(mod_alias) and RewriteRule(mod_rewrite)

lucy24

12:01 pm on Aug 9, 2012 (gmt 0)

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



Is it your own server? You mentioned a config file earlier. If you know for certain which module will execute first, mod_alias or mod_rewrite, you can write your rules accordingly.

In general mod_alias executes after mod_rewrite. (And, on my www site, mod_setenvif executes before both. I tested. But on MAMP, mod_alias and mod_rewrite are the very last modules to load and therefore the first to run.) Unless of course you've set it up to go the other way around. So you might have something that was only meant to be a rewrite slamming into a mod_alias Redirect and getting treated as a whole new request and getting redirected "outside".

If there's no overlap between the files they can apply to-- for example, one directory gets only Redirect and another gets only RewriteRule-- it should be safe.

Apache themselves say emphatically that there are times when mod_alias is preferable to mod_rewrite. But then, they've definitely got their own server ;)

If you do use rules from more than one module, put the groups of rules in your config file in the order they will execute. This has no effect on the server's behavior, but helps you remember which comes first.