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

merging htaccess to reach destination with 1 hop

 2:09 pm on May 6, 2012 (gmt 0)

I need help in rewrite rules for my blog and forum. May be a bit complicated so I am listing down the information and questions in point form for easier understanding.

The blog is running on Wordpress.
1. Installed in a /blog/ subdirectory.
Example: www.website.com/blog/

2. OLD permalink format
Example: www.website.com/blog/archives/YEAR/MONTH/DATE/%postname%/
NEW permalink format
Example: www.website.com/blog/%postname%/

- I have the following rewrite rule to strip the /archives/year/month/date/ from the URL.

RewriteRule ^archives/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /blog/$4 [R=301,NC,L]
RewriteRule ^archives/category/(.*)?$ /blog/category/$1 [R=301,NC,L]
RewriteRule ^archives/author/(.*)?$ /blog/author/$1 [R=301,NC,L]
RewriteRule ^archives/tag/(.*)?$ /blog/tag/$1 [R=301,NC,L]

3. Used to have translation plugin installed which adds the a two letter language code at the end of the permalink.
Example: www.website.com/blog/archives/YEAR/MONTH/DATE/%postname%/de/

- I have the following rules to redirect the translated pages to the original URL.
RewriteRule ^(.*)/(ar|bg|ca|cs|cy|de|da|el|es|es_MX|fi|fr|
sl|sr|sv|tl|tr|uk|vi|zh|zh_TW|zh-CN)/ /blog/$1/ [R=301,NC,L]
RewriteRule ^(ar|bg|ca|cs|cy|de|da|el|es|fi|fr|he|
sl|sr|sv|tl|th|tr|uk|vi|zh|zh-tw)/(.*)/ /blog/$2/ [R=301,NC,L]
RewriteRule ^(ar|bg|ca|cs|cy|de|da|el|es|es_MX|fi|fr|he|
sl|sr|sv|tl|th|tr|uk|vi|zh|zh-CN|zh-tw|zh_TW)/ http://www.website.com/blog/ [R=301,NC,L]

1. How do I create a rewrite rule for year and month archives so that it strips of the /archives/ from the URL?

Example of year archives: www.website.com/blog/archives/2006/
I want the above to become www.website.com/blog/2006/

Example of year and month archives www.website.com/blog/archives/2006/09/
I want this to become www.website.com/blog/2006/09/

2. How can I merge the language and new permalink rewrite rules so that visitors and robots reaches the destination with only one hop? With the current rewrite rules, when someone visits [website.com...] first it strips off the /de/ from the end of the URL, and then followed by stripping off the /archives/2006/09/01/ from the URL. That's two hops.

The forum is running on vBulletin.
1. Installed in a /forum/ subdirectory.
Example: www.website.com/forum/

2. Has vBSEO plugin installed.

3. Used to have translation plugin installed which adds the a two letter language code at the beginning of the URL.
Example: www.website.com/forum/de/movies/29191-top-movies-list.html

- I have the following rules to redirect the translated pages to the original URL.

RewriteRule ^/?(af|sq|ar|be|bg|ca|zh-CN|hr|cs|da|nl|en|et|
fa|pl|pt|ro|ru|sr|sk|sl|es|sw|sv|zh-TW|th|tr|uk|vi|cy|yi)/$ /forum/index.php [L,R=301]
RewriteRule ^/?(af|sq|ar|be|bg|ca|zh-CN|hr|cs|da|nl|en|et|
fa|pl|pt|ro|ru|sr|sk|sl|es|sw|sv|zh-TW|th|tr|uk|vi|cy|yi)/(.*)?$ /forum/$2 [L,R=301]

1. I am planning to move the forum from subfolder to a subdomain where it will become forum.website.com. I found two rewrite rules and not sure what are the differences and which will work better.

RewriteRule (.*) http://forum.website.com/$1 [L,R=301]
RewriteRule ^(.+)$ http://forum.website.com/$1 [L,QSA]

2. I will also need to merge the language code rewrite rule with the subdomain rewrite rule above. Reason is I found out that there are already 2 hops when someone visit the translated page on the forum. First it strips off the language code, and then it hops again to the correct URL by referring to the postid on the URL. If it hops again to the subdomain, it will be 3 hops and that is the danger zone.

Matt Cutts has already warned about chained redirects and advises keeping it to 1 or 2 hops.

Any help will be much appreciated. If the help that I need is way too complicated, I am willing to pay for your service. Thanks!

[edited by: tedster at 4:46 pm (utc) on May 7, 2012]
[edit reason] line breaks added to prevent side scrolling [/edit]



 8:49 pm on May 6, 2012 (gmt 0)

I'm a little confused. (Also a little dizzy. You may not realize that most browsers don't automatically wrap overlong lines, and I don't happen to have a 42" monitor.) It seems as if you already have the rules you need, such as

RewriteRule ^archives/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /blog/$4 [R=301,NC,L]

except for details. For example there's no reason to capture the year-month-day pieces if you won't be reusing them. And you should never say [NC] when something will be captured and reused; it just leaves you with an infinite number of URLs. Always include your preferred protocol and domain when redirecting. Otherwise the server will reattach whatever the user requested in the first place, which may not be the form you want.

RewriteRule (.*) http://www.example.com/$1 [L,R=301]
RewriteRule ^(.+)$ http://www.example.com/$1 [L,QSA]

QSA is not needed in either rule, because it is the default behavior of mod_rewrite. The flags say that Rule 2 is a Rewrite, but the protocol-plus-domain makes it into a Redirect just like Rule 1-- except that it's a 302 instead of the preferred 301. Anchors here are superfluous. By default, Regular Expressions start as soon as they can and go on as long as you can, so anchors are only needed when you're looking for some specific text in a specific location.

Use example.com (or dot.anything) in your examples. Subdomains other than with/without www don't work, darn it, but you can use any tld you like.

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