homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess help
detect URL format and remove from URL

5+ Year Member

Msg#: 4451878 posted 4:06 pm on May 10, 2012 (gmt 0)

I would like to permanently redirect the below URL:




#*$!X and YY are all numbers.
The four Xs are actually year and the 2 YYs are month.

I tried the below rewrite rule and it don't work. Any help is much appreciated.

RewriteEngine On
RewriteBase /blog/
RewriteRule ^archives/([0-9]+)/([0-9]+)/ /blog/$3 [R=301,NC,L]

[edited by: incrediBILL at 4:59 pm (utc) on May 10, 2012]
[edit reason] fixed URLS, use Example.com [/edit]



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4451878 posted 8:36 pm on May 10, 2012 (gmt 0)

Are you rewriting





You have "blog" twice, and there is no capture $3. (Um, Bill, you didn't accidentally delete a couple of parentheses did you?)

The RewriteBase declaration refers to the target, not the pattern. But it's irrelevant here because you are Redirecting, not Rewriting, so you should give the complete protocol-plus domain in your Target.

Be as specific as possible. If there are exactly four digits followed by exactly two digits, say so in the Rule:


are two possible formats. You can capture the whole thing together, since you'll be reusing it in its original form.

Now here is the problem. You are using mod_alias syntax, where the rest of the URL is reattached to the end of both pattern and target. mod_rewrite doesn't work that way; it does a complete replacement. So if there is anything after /archives/ that you want to keep and reuse, you have to capture it, as in


Again, anything that's being reused in the original order can be captured as a package.

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