301 redirect

Discuss practical ways rearrange URLs using mod_rewrite.

301 redirect

Postby 301redirect » Tue Mar 10, 2009 12:37 pm

Hello;
I would like to redirect old pages to new one for example:
when i click category.php?categoryId=1000 i should redirect visitors and google bot to category_Flowers_1000
is it possible via htaceess?

RewriteEngine on
RewriteRule ^category_([a-zA-Z0-9&-\+\.\_'"]*)_([0-9]*) category.php?categoryId=$2 [L,NC]
RewriteRule ^item_[a-zA-Z0-9&-\+\.\_'"]*_([0-9]*)_([a-zA-Z0-9&-\+\.\_'"]*)_([0-9]*) products.php?categoryId=$2&productId=$3 [L,NC]

i added R=301 but i doesnt work out.
301redirect
 
Posts: 1
Joined: Tue Mar 10, 2009 9:50 am

Postby richardk » Tue Mar 10, 2009 12:48 pm

How will mod_rewrite find out 1000 means adding Flowers? If you have access to the httpd.conf file you could use a RewriteMap. If you do not you will need seperate rules or to write a script to do it.

To redirect one URL to another is not as simple as adding R=301, you must match the old URL (/old.php?url=1 to /newurl1)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?url=([^&]+)(&.*)?$ [NC]
RewriteRule ^old\.php$ /newurl%2? [R=301,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 19 guests

cron