homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Question about 301 redirect using a wildcard

 4:28 am on Feb 10, 2014 (gmt 0)

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



 4:54 am on Feb 10, 2014 (gmt 0)

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.


 12:54 pm on Feb 10, 2014 (gmt 0)

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?


 9:20 pm on Feb 10, 2014 (gmt 0)

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).

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved