View Full Version : mod_rewrite help?
pete3005
04-08-2003, 06:07 AM
Does anyone know how to use mod_rewrite?
I tried this:
RewriteEngine on
RewriteRule ^products/(.*)/(.*).php /products.php?
cat=$1&subcat=$2
Its on my domain so I am wanting to use it at http://www.mysite.com/silver/products.php
I put the .htaccess in /silver/
I got a 500 server error so I know I am doing something wrong.
I'm trying to go from this:
/silver/products.php?cat=1&subcat=20
to:
/silver/products/1/20.php
any tips or links greatly appreciated :)
Thanks in advance
Pete
I tried this:
RewriteEngine on
RewriteRule ^products/(.*)/(.*).php /products.php?
cat=$1&subcat=$2
Its on my domain so I am wanting to use it at http://www.mysite.com/silver/products.php
I put the .htaccess in /silver/
I got a 500 server error so I know I am doing something wrong.
I'm trying to go from this:
/silver/products.php?cat=1&subcat=20
to:
/silver/products/1/20.php
Pete,
The rewrite you have above suggests that you are wanting to have the redirect to change:
http://www.mysite.com/silver/products/1/20.php
to:
http://www.mysite.com/silver/products.php?cat=1&subcat=20
rather than
http://www.mysite.com/silver/products.php?cat=1&subcat=20
to:
http://www.mysite.com/silver/products/1/20.php
as you state.
Here's an example of both:
In both cases the .htaccess file should be in /silver/
First going from:
http://www.mysite.com/silver/products/1/20.php
to:
http://www.mysite.com/silver/products.php?cat=1&subcat=20
RewriteEngine on
RewriteBase /silver/
RewriteRule ^products/([0-9]+)/([0-9]+)\.php products.php?cat=$1&subcat=$2 [R]
Now going from:
http://www.mysite.com/silver/products.php?cat=1&subcat=20
to:
http://www.mysite.com/silver/products/1/20.php
RewriteEngine on
RewriteBase /silver/
RewriteCond %{QUERY_STRING} cat=([0-9]*)&subcat=([0-9]*)
RewriteRule ^products.php products/%1/%2.php? [R]
A few things to note:
If you miss the [R] off the end of the rewrite rule, the redirection will work internally, ie it will bring up the correct page, but the url in the address bar won't change.
In the second example the ? after the php means the the query string is dropped from the redirected url, if you don't include the ? the query string will be appended, so if you change:
RewriteRule ^products.php products/%1/%2.php? [R]
to:
RewriteRule ^products.php products/%1/%2.php [R]
this will redirect:
http://www.mysite.com/silver/products.php?cat=1&subcat=20
to:
http://www.mysite.com/silver/products/1/20.php?cat=1&subcat=20
Hope that helps
pete3005
04-10-2003, 02:36 AM
Thanks for the help Mort, I tried initially without luck but I am pressed for time so I will look at this in with the next 48 hours, but just wanted to say thanks for the detailed reply, much appreciated :)
Pete
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.