I currently have links on my website in the form of:- http://example.com/products.php?cat=X
I want that once taken to the destination of the link, the url displays something like:- http://example.com/new
.
The file on my server is the same file, but only the url should appear neater without me having to change any of the links.
I tried the following, but found it only useful if I explicitly changed the internal links:-
RewriteRule ^new$ products.php?cat=10
RewriteCond %{QUERY_STRING} =cat=10
RewriteRule ^products.php$ new [R,L]
RewriteRule ^new$ products.php?cat=10 [L]
Check the original requested URL in the request line:
RewriteCond %{THE_REQUEST} ^GET /products\.php\?([^&]*&+)*cat=X
RewriteRule ^products\.php$ /new? [L,R=301]
But it will probably be easier if you do that with PHP (see $_SERVER['REQUEST_URI']
).