| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|Question about 301 redirect using a wildcard|
I have a series of dynamic URLs from the old site that need to be redirected to the static URL on the new site. I think I need to use a wildcard in the rewrite rule but not sure.
Example -- multiple versions of the same URL:
I want to redirect them all to:
Sooo, something like this?:
Thanks all for help
I hope that was an artifact of cutting-and-pasting. I think your server will explode if you try to feed it a RewriteRule with no spaces.
:: detour to test site ::
Yup. (This is a relief. Last time I checked something, I turned out to be 100% mistaken.)
Once you're in mod_rewrite, all you have to do is leave off the closing anchor:
will match anything that begins that way. You don't need the (.*), because you're not capturing. Keep the opening anchor, as it will shave a nanosecond or two off processing.
Thank you. And a clarification question about redirect loops:
If my rule is:
RewriteRule ^page-category/page/ http://example.com/page-category/page/ [R=301]
and a user types in the new preferred URL http://example.com/page-category/page/, will that keep redirecting to itself?
Oops, yes, my bad. If the target and the pattern are the same, you will always get an infinite loop. So you'll need to add one character to the rule and make the pattern
. here means "anything at all". That way your target and pattern are different and there's no loop.
Edit: Also make sure the rule includes the [L] flag. It isn't implied by [R=301] the way it would be for [G] or [F] (or, I think, any non-300 code).
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved