Reputation: 2235
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.
Upvotes: 0
Views: 461
Reputation: 9539
Try the following. Ensure that there are 2 spaces between \.php\
and `[NC]
RewriteEngine on
RewriteBase /
#any url with .php and no anchor or query string
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^\ ]+)\.php\ [NC]
RewriteRule ^ /%1 [R=301]
Upvotes: 1