I have came accross a problem that every .htaccess query I’ve tried wasn’t worked out ! I have URLs like this:
http://www.example.com/index.php?x=product
And I want to change it to a user friendly URL like this:
http://www.example.com/product/
Or it can be:
http://www.example.com/product.php
I’ve tried this code below:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^x=product$
RewriteRule ^index.php.*$ http://www.example.com/product.php? [R=302,L]
Now, it is redirecting perfectly, but this is not the problem. I’ve used this for only SEO so I must include http://www.example.com/index.php?x=product in the product.php file. Any help can be precious, thanks…
2
Answers
You can use this code in your
DOCUMENT_ROOT/.htaccess
file:This will redirect
/index.php?x=product
to/product/
and will rewrite it internally to/index.php?x=product
in 2nd rule.You don’t need to put anything in the product.php file. Make sure there is a .htaccess in the directory that has the files you want to make url/seo friendly.
To have it SEO friendly make sure its in this format
http://www.example.com/product/
nothttp://www.example.com/product.php
if you must have a file extension, have it in
http://www.example.com/products.html
(you want to tell the search engine the page isn’t dynamic although it is to get better pagerank)Insert this in your .htaccess
the
(.*)
pulls the elements out and puts them in variables $1