views:

222

answers:

2

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

A: 
RewriteCond %{QUERY_STRING} =cat=10
RewriteRule ^products.php$ new [R,L]

RewriteRule ^new$ products.php?cat=10 [L]
Ignacio Vazquez-Abrams
I tried this but I would still have to change the link address inside my php files in order to take me to http://example.com/new. I want a solution where I would not have to change the internal links.
nitbuntu
The first rule rewrites `products.php?cat=10` to `new` in the browser, and the second rule rewrites `new` to `products.php?cat=10` internally in httpd.
Ignacio Vazquez-Abrams
The thing is that even after entering these in my .htaccess, when I click on a link to products.php?cat=10, I am not taken to /new.
nitbuntu
My apologies, I had a typo in RewriteCond. Fixed now.
Ignacio Vazquez-Abrams
A: 

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']).

Gumbo