Link to home
Start Free TrialLog in
Avatar of thijs321
thijs321

asked on

RewriteRule in .htaccess isn't working properly, how can this be fixed?

We've made some changes to the website including several url's. Since some other websites haven't updated their forms/url's yet they are linking to the wrong page. We've come up with the RewriteRule you can find in the Code Snippet, but it's not working at all.

Url at the old website:
http://website.com/search/?keywords=[...]
or
http://website.com/search/?keywords=[...]&place=[...]

And most of the time it has &button=Search at the end of it.

It needs to be rewrited to:
search.php?s=[keywords]&p=[place].
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
 
  RewriteRule ^search/\?keywords=([^&]*)(?:&place=([^&]*))?.*$ search.php?s=$1&p=$2 [R=301,NC]
 
  # Some other rules.
  # ...
</IfModule>

Open in new window

Avatar of fruey
fruey
Flag of France image

This should work better (but only if keywords & place are always in that order)
#something more like this
RewriteRule ^search/\?.*keywords=([^&]*).*&place=([^&]*) search.php?s=$1&p=$2 [R=301,NC]
#cover the other order in URL (place first)
RewriteRule ^search/\?.*place=([^&]*).*&keywords=([^&]*) search.php?s=$2&p=$1 [R=301,NC]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of thijs321
thijs321

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial