views:

52

answers:

2

Hi,

I'm a complete n00b when it comes to regular expressions. I need these redirects:

(1)

www.mysite.com/bike.php?id=001&product=Product-Name&source=Source-Name
should become -> www.mysite.com/Source-Name/001-Product-Name

(2)

www.mysite.com/car.php?id=002&product=Product-Name&source=Source-Name
should become -> www.mysite.com/Source-Name/002-Product-Name

(3)

www.mysite.com/moto.php?id=005&product=Product-Name&source=Source-Name
should become -> www.mysite.com/Source-Name/005-Product-Name

(4)

www.mysite.com/stores.php?id=002&name=Store-Name
should become -> www.mysite.com/002-Store-Name

Edit: I should have clarified, there are 3 product pages, which should all redirect to the same format URL

Any help much appreciated :)

+1  A: 
RewriteCond %{REQUEST_URI} www.mysite.com/(.+)/(\d+)-(.+)  /products.php?id=$2&product=$3&source=$1

RewriteCond %{REQUEST_URI} www.mysite.com/(\d+)-(.+)  /products.php?id=$1&name=$2

I think it work's well ;)

fermin
+1  A: 
RewriteEngine On
RewriteRule ^(\d+)-(.+)$ /stores.php?id=$1&name=$2 [L]
RewriteRule ^(.+)/(\d+)-(.+)$ /products.php?id=$2&product=$3&source=$1 [L]
kemp
Sorry, how would I reverse those rules? Thanks :)
Boris
kemp
Boris
That's exactly what the rules I wrote do :)
kemp
hmm.. doesn't seem to be working.. Would it matter if everything's in the /dev directory? eg. http://mysite.com/dev/products...
Boris
It's just redirecting to my homepage.
Boris
Well I wrote `/stores.php` assuming it was in the webroot, if that script is located elsewhere, update the path in the rule accordingly
kemp
Boris
Maybe you have other rewrite rules?
kemp