I’m trying to 301 redirect pages with a .php extension to their extensionless version. Using the rule below, pages with a query parameter fail (signup.php?login=true) or result in a redirect loop.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ /$1 [R=301]
I’d therefor like to exclude dynamic urls (It doesn’t seem to make sense to rewrite them anyway). I’ve written the code below but the condition still seems to match dynamic urls.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ /$1 [R=301]
Can anyone help me adjust my condition to prevent dynamic urls from being rewritten.
Try the following. Ensure that there are 2 spaces between
\.php\and `[NC]