I’ve created a controller file which handles redirecting users to the proper url, I want to direct certain traffic to this controller and not affect the rest. http://website.com/shows.php?id=review-1 is an example of the url I want to send to the controller.
What I’ve concocted thus far is the following RewriteRule which causes a site-wide server 500 Server Error.
RewriteCond %{THE_REQUEST} ^GET\s/shows\.php\?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-[0-9]+(?:&|$) [NC]
RewriteRule ^ /controller.php [QSA,L]
Removing the -[0-9]+ from the %{QUERY_STRING} condition gets rid of the site-wide 500 Server Error, but doesn’t work. The following RewriteRule that I’m trying to replace works just fine.
RewriteCond %{THE_REQUEST} ^GET\s/shows\.php\?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-1(?:&|$) [NC]
RewriteRule ^ /review/1/super-baseball-2020/? [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)/([0-9]+)/([a-z0-9-]+)?/?$ /shows.php?id=$1-$2 [QSA,L,NC]
The end result is that a user who goes to http://www.website.com/shows.php?id=review-1 will end up at http://www.website.com/controller.php?id=review-1 which will deal with handling the 301 redirect.
I still don’t know why you’re trying to make simple things into complex ones 😉
6 minutes to find+test. Here’s what should work:
PS: Like Devin, I don’t get/know why
(?:^|&)works…