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:

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

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

Open in new window

Apache Web Server

Avatar of undefined
Last Comment

8/22/2022 - Mon

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


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes