help with permanent redirection

Discuss practical ways rearrange URLs using mod_rewrite.

help with permanent redirection

Postby weebo » Tue Jul 15, 2008 2:09 pm

Hi I have such a rules to shorten my long url and make them more user friendly:

RewriteRule ^article/([0-9]+)/(.+)$ /go/_articles/?id=$1 [QSA,L] > www.mysite.com/article/1/some_title shows www.mysite.com/go/_articles/?id=1 content
RewriteRule ^article/([0-9]+)/(.+)/category/([0-9]+)/(.+)$ /go/_articles/index.php?id=$1&category=$3 [QSA,L] > www.mysite.com/article/1/some_title/cat ... /some_name shows www.mysite.com/go/_articles/?id=1&category=1 content
RewriteRule ^news/([0-9]+)/(.+)$ /go/_news/?id=$1 [QSA,L] > www.mysite.com/news/1/some_title shows www.mysite.com/go/_news/?id=1 content
RewriteRule ^help$ /go/_files/?file=help.html [QSA,L] > www.mysite.com/help shows www.mysite.com/go/_files/?file=help.html content
RewriteRule ^contact$ /go/_files/?file=contact.html [QSA,L] > www.mysite.com/contact shows www.mysite.com/go/_files/?file=contact.html content


But I also want to have a permanent redirection for all this rules. When someone enter the old URL (like www.mysite.com/go/_files/?file=help.html) I want him to be redirected to the new one (like www.mysite.com/help) so the old URL will be no longer available, for search engines too.

I have read many articles especially with 301 redirection examples, but I can't write a rule that do that. Can you help me?
weebo
 
Posts: 1
Joined: Tue Jul 15, 2008 1:57 pm

Postby richardk » Tue Jul 15, 2008 3:24 pm

RewriteRule ^article/([0-9]+)/(.+)$ /go/_articles/?id=$1 [QSA,L]
RewriteRule ^news/([0-9]+)/(.+)$ /go/_news/?id=$1 [QSA,L]

www.mysite.com/article/some_title/1 shows www.mysite.com/go/_articles/?id=1 content, www.mysite.com/news/some_title/1 shows www.mysite.com/go/_news/?id=1 content,

Mod_rewrite can not do these redirects. It cannot get the article title from the original URL.

For the rest
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Stop loops.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Match the query string variable file.
RewriteCond %{QUERY_STRING} ^(.*&)?file=(help|contact)\.html(&.*)?$ [NC]
# Match the file and redirect.
RewriteRule ^go/_files/?$ /%2 [NC,R=301,L]

RewriteRule ^article/([0-9]+)/(.+)$ /go/_articles/?id=$1 [QSA,L]
RewriteRule ^news/([0-9]+)/(.+)$ /go/_news/?id=$1 [QSA,L]
RewriteRule ^(contact|help)$ /go/_files/?file=$1.html [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 60 guests

cron