Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess help

detect URL format and remove from URL

4:06 pm on May 10, 2012 (gmt 0)

New User

5+ Year Member

joined:May 27, 2008
votes: 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]

8:36 pm on May 10, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
votes: 286

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.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members