问题
I'm trying to redirect uppercase URL's to lowercase, but having a bit of a nightmare with it! (Mainly because my .htaccess knowledge is lacking!)
Currently I have:
<IfModule mod_speling.c>
CheckSpelling on
</IfModule>
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
Which works fine, but the CMS I'm using puts pagination links in the URL such as http://website.com/blog/P8
or http://website.com/blog/P10
and because the URL's have an uppercase P (Which seems to be required) they are 404 or 301 redirecting.
Is there a rule i could add to make it not pick up on segments of the URL that have a P
and immediately have at least one numerical character after it? Regex maybe?
Any help would be appreciated!
回答1:
You can create an exception like this:
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteCond %{REQUEST_URI} !/P\d+/?$ [NC]
RewriteRule (.*) ${lc:$1} [R=301,L]
Or using negative lookahead:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(?!.*/P\d+/?$)(.*)$ ${lc:$1} [R=301,L]
来源:https://stackoverflow.com/questions/35358972/redirect-uppercase-urls-to-lowercase-except-htaccess