homepage Welcome to WebmasterWorld Guest from 54.197.15.196
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 redirect works partially
raymondcc

5+ Year Member



 
Msg#: 4578445 posted 4:01 am on May 28, 2013 (gmt 0)

I am running a Wordpress based website. Lucy from WebmasterWorld helped me written the following htaccess redirect.

RewriteRule ^archives/(category|author|tag)/((?:[a-z]{5,}/|feed/)+)(page/[0-9]+/)?(?:[a-z][a-z](?:_MX|_BR|_TW|-CN)?/)? http://www.example.com/blog/$1/$2$3 [R=301,L]

The above should automatically strip off the /archives/ for the 2 example URLs below. I've tested it and it works.
http://www.example.com/blog/archives/tag/delete/
http://www.example.com/blog/archives/tag/recover/

Weirdly, I can't figure out why the htaccess is not stripping off the /archives/ for the URL below which is actually the same as the 2 URLs above.
http://www.example.com/blog/archives/tag/text/

I thought this is caused by Wordpress trying to guess the correct URL. Added the code below to functions.php but didn't solve the problem.

add_filter('redirect_canonical', 'stop_guessing');
function stop_guessing($url) {
if (is_404()) {
return false;
}
return $url;
}


Any advice would be much appreciated.

[edited by: phranque at 4:32 am (utc) on May 28, 2013]
[edit reason] please use example.com [/edit]

 

Dideved



 
Msg#: 4578445 posted 7:08 am on May 28, 2013 (gmt 0)

At a glance, the reason seems to be because the pattern requires the word after "/tag/" be at least 5 letters, but "text" is only 4 letters. As for *why* the pattern requires at least 5 letters... well... that's a question only you and Lucy can answer. Personally, I think the whole pattern overly specific and unnecessarily complicated.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4578445 posted 9:24 am on May 28, 2013 (gmt 0)

The pattern is likely very specific such that it doesn't accidentally match other URL requests that it should not match.

This is one of the many cases where the oft recommended ^(.*)/(.*)/(.*)(.*)?((.*)_(.*))? etc, would wreak havoc.

That said, the {5,} requirement is a bit odd. You'll need to see what requests, if any, with length 1, 2, 3 or 4 this part must never match before altering the pattern.

lucy24

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



 
Msg#: 4578445 posted 6:41 pm on May 28, 2013 (gmt 0)

The pattern is likely very specific such that it doesn't accidentally match other URL requests that it should not match.

Yes, there were clear and specific reasons why the RewriteRules had to be worded exactly that way. The quoted line is only one piece of a much longer htaccess.

There are also clear and specific reasons why I will not provide any further answers in this thread :(

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