First, make sure you have no directory in your web root named "search".
Then, add what's between the horizontal lines below to your .htaccess file:
--------------------------------------
RewriteEngine On
# If the file or folder does not exist: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Take all requests for "/search": RewriteCond %{REQUEST_URI} ^/search$ # And show the old search page to them instead: RewriteRule ^search detail.php?id=1&srch=cat [L]
--------------------------------------
Now if you want people who are still using the old address to be redirected to the new one, then add these rules as well:
--------------------------------------
# If they have loaded the "detail.php" page: RewriteCond %{REQUEST_URI} ^/detail\.php$ # And the query string (the part after the ? mark) is "id=1&srch=cat": RewriteCond %{QUERY_STRING} ^id=1&srch=cat$ # Then redirect to the new, search-engine friendly URL: # (Note: the ? at the end says not to pass along the query string, # the R says to redirect, and the L says this is the last rule, # so if it matches, implement it and don't process later ones) RewriteRule ^.* http://www.yourdomain.com/search? [R,L]
--------------------------------------
or, if you want search engines to make permanent note of the new address, replace the final line above with:
--------------------------------------
RewriteRule ^.* http://www.yourdomain.com/search? [R=301,L]
--------------------------------------
I haven't tested this since it would involve overwriting my own htaccess files, but if there are any glitches (like Apache errors) then refer to this for syntax: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
And I also found this an excellent tutorial on mod_rewrite: http://forums.devshed.com/apache-development-15/mod-rewrite-guide-common-requests-267522.html
|