Question regarding redirection using htaccess. On a GET search form submit I get the following url:
http://www.example.com/search/?criteria=foo&filter=all&date=all&submit=search&page=1
The above works fine. Then I have this rewrite rule in my htaccess:
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ search.php?criteria=$2&filter=$3&date=$4&submit=$1&page=$5 [L]
The above also works fine. It allows me to use the following structure for my search results:
http://www.example.com/search/foo/title/all/1/
Now my question is when I click submit I would like it to use the new clearner url structure however it uses the messier one with the question marks and the equal signs. Now automatically I was thinking maybe I have to do a redirect in PHP however if I can do it with htaccess I would be happier as it means cleaner code.
I also understand I can do this with JavaScript by intercepting the click and creating the seo friendly url but again if their is a way with htaccess I would prefer that.
Hope you understand what im trying to achieve and many thanks for reading,
fl3x7
p.s im pretty new to htaccess so if you can explain/ guide etc that would be great
You cannot do it solely with .htaccess.
You can do it with javascript (intercept the onclick event, construct the url string using the user entered data then redirect the page to this url), but this is not really reliable considering that javascript runs on the client side.
My suggestion is to use PHP for this. The process is the same, but I'll use POST instead of GET as a method for the form. Before the page gets rendered, detect the $_POST data and construct the $url using it. Then redirect the page to that $url, using header("Location: ".$url); It will be best to use exit(); after this, to make sure that the code below it will not get executed as the redirect is made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With