Redirect uppercase URL's to lowercase except *** - htaccess

那年仲夏 提交于 2019-12-23 19:41:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!