Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

php - Convert url to lower case using htaccess except query string

Am struggling with a htaccess problem.

I need to convert all the URLs from uppercase to lowercase. But the query string alone should be the same.

For example,

www.tESTUrl.com/sOMePath/?q=SomeStringHere

should be converted as,

www.testurl.com/somepath/?q=SomeStringHere

Please help to fix this. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First You have to add this to your httpd.conf:

RewriteMap lc int:tolower

Then paste the below code into your .htaccess

RewriteEngine On
RewriteBase / 
RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}} [L,R=301]

This code redirct the url like from

www.tESTUrl.com/sOMePath/?q=SomeStringHere

to www.testurl.com/somepath/?q=SomeStringHere


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...