Call us! (ID:64475)
+1-727-546-4678
HomeWeb Hosting FAQHow to redirect URL:s with Caps to Lowercase using .htaccess

How to redirect URL:s with Caps to Lowercase using .htaccess

Question: My website has Caps its URL:s, and I want to redirect them to lowercase. How can I do that with .htaccess?

Answer: That is a good question. Many don't know that Google actually considers case and reckon two identical URLs as two different addresses if they differ in case. This means, that if you migrate your website from a CMS where uppercase was used in the URL, into WordPress, you'd really want to make 301 redirects from caps to all lowercase. You can do that by adding this portion of code to your .htaccess file:

# BEGIN Caps Redirect by ServeU.net
# If there are caps, set HASCAPS to true and skip next rule
RewriteRule [A-Z] - [E=HASCAPS:TRUE,S=1]

# Skip this entire section if no uppercase letters in requested URL
RewriteRule ![A-Z] - [S=28]

# Replace single occurance of CAP with cap, then process next Rule.
RewriteRule ^([^A]*)A(.*)$ $1a$2 [DPI]
RewriteRule ^([^B]*)B(.*)$ $1b$2 [DPI]
RewriteRule ^([^C]*)C(.*)$ $1c$2 [DPI]
RewriteRule ^([^D]*)D(.*)$ $1d$2 [DPI]
RewriteRule ^([^E]*)E(.*)$ $1e$2 [DPI]
RewriteRule ^([^F]*)F(.*)$ $1f$2 [DPI]
RewriteRule ^([^G]*)G(.*)$ $1g$2 [DPI]
RewriteRule ^([^H]*)H(.*)$ $1h$2 [DPI]
RewriteRule ^([^I]*)I(.*)$ $1i$2 [DPI]
RewriteRule ^([^J]*)J(.*)$ $1j$2 [DPI]
RewriteRule ^([^K]*)K(.*)$ $1k$2 [DPI]
RewriteRule ^([^L]*)L(.*)$ $1l$2 [DPI]
RewriteRule ^([^M]*)M(.*)$ $1m$2 [DPI]
RewriteRule ^([^N]*)N(.*)$ $1n$2 [DPI]
RewriteRule ^([^O]*)O(.*)$ $1o$2 [DPI]
RewriteRule ^([^P]*)P(.*)$ $1p$2 [DPI]
RewriteRule ^([^Q]*)Q(.*)$ $1q$2 [DPI]
RewriteRule ^([^R]*)R(.*)$ $1r$2 [DPI]
RewriteRule ^([^S]*)S(.*)$ $1s$2 [DPI]
RewriteRule ^([^T]*)T(.*)$ $1t$2 [DPI]
RewriteRule ^([^U]*)U(.*)$ $1u$2 [DPI]
RewriteRule ^([^V]*)V(.*)$ $1v$2 [DPI]
RewriteRule ^([^W]*)W(.*)$ $1w$2 [DPI]
RewriteRule ^([^X]*)X(.*)$ $1x$2 [DPI]
RewriteRule ^([^Y]*)Y(.*)$ $1y$2 [DPI]
RewriteRule ^([^Z]*)Z(.*)$ $1z$2 [DPI]

# If there are any uppercase letters, restart at very first RewriteRule in file.
RewriteRule [A-Z] - [N]

RewriteCond %{ENV:HASCAPS} TRUE
RewriteRule ^/?(.*) /$1 [R,L]
# END Caps Redirect by ServeU.net

3 Comments

  1. emmanuel bassey
    Posted October 7, 2019 at 5:13 pm | Permalink

    You have really saved my day with this, thanks alot

  2. JKSRS GROUP
    Posted January 4, 2020 at 5:29 am | Permalink

    saved my day with this, thanks more

  3. Jyoti
    Posted March 21, 2020 at 5:55 am | Permalink

    Thanks a lot. You saved my day.
    God bless you.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*