Why Is Rewrite Rule Throwing Error Message "Moved Permanently?"

sharingsunshine
sharingsunshine used Ask the Experts™
on
This is a follow-on to this question https://www.experts-exchange.com/questions/29120630/How-To-Enable-Rewrite-On-Linux-2.html - I followed the advice but forgot that wordpress will overwrite what is within the wordpress block so I am now moving it out of the block.

# END W3TC Page Cache core

RewriteCond %{QUERY_STRING} controller=product [NC]
RewriteCond %{QUERY_STRING} id_product=26 [NC]
RewriteRule ^/?index\.php$ /product/geranium-15-ml-100-pure-essential-oil/ [NC,R=301]

RewriteCond %{QUERY_STRING} controller=cms [NC]
RewriteCond %{QUERY_STRING} id_cms=([0-9]+)\%3F [NC]
RewriteRule ^/?index\.php$ /index.php?controller=cms&id_cms=%1 [NC,R=301]

RewriteCond %{QUERY_STRING} controller=product [NC]
RewriteCond %{QUERY_STRING} id_product=([0-9]+)\%3F [NC]
RewriteRule ^/?index\.php$ /index.php?controller=product&id_product=%1 [NC,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Open in new window


The first re-write rule produces this error:  

https://gyazo.com/9741f64223879ee3f42407f1985e4d5e

The other 2 rules work fine so why is this rule not working and producing this error?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Principal Software Engineer
Commented:
I believe your first three rules should have "L" in the flags so that when one hits, the URL cannot be rewritten further.

Make that change, turn on rewrite debugging at level 4, and see what the rewrite log shows is happening.

Author

Commented:
You're correct, but it also needs a "?" at the end to drop the query string.

Thanks for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial