Help with Mod_rewrite

Using mod_rewrite to handle various content issues

Help with Mod_rewrite

Postby jpdguzman » Wed Aug 02, 2006 7:09 pm

If have the following url and i want to transform it using mod rewrite. The sample url is this:

Code: Select all
Product.php?item=90


This format has been through my codes. I wonder if there are any ways i can change this format to:
Code: Select all
Products/90


Is there any way that if i click the original URL (Product.php?item=90)
it would redirect automatically to the pretty URL format.

I've tried different combination but none of them seems to work.
I've tried using:

Code: Select all
RewriteRule ^Product.php?item=([0-9]+)$ Product/$1/ [R]
RewriteRule /Product/([0-9]+)/ Product.php?item=$1 [L]


The following code seems to be recurssive.. once i run the whole thing... it doesn't stop. Can you help me...

Thanks.
jpdguzman
 
Posts: 1
Joined: Wed Aug 02, 2006 6:59 pm

Postby richardk » Thu Aug 03, 2006 5:11 am

it would redirect automatically to the pretty URL format.

You should be editing the script to output the new format of URI. You should only use the "/Product.php?item=123 --> /Products/123/" part of the mod_rewrite so people (and SEs) with the old links can still get to the content.

Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

# force trailing slash, optional.
RewriteRule ^Products/([0-9]+)$ /Products/$1/ [R=301,L]

# /Products/123/ --> /Product.php?item=123
RewriteRule ^Products/([0-9]+)/?$ Product.php?item=$1 [QSA,L]

# /Product.php?item=123 --> /Products/123/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^item=([0-9]+)$
RewriteRule ^Product\.php$ /Products/%1/ [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Content

Who is online

Users browsing this forum: No registered users and 0 guests

cron