Small WordPress trick to change from small letters to big letters

Let’s say you use WordPress.

You may know, for SEO purposes, it’s better to redirect a user visiting:

site.com/BigLetterURL to:

site.com/bigletterurl

You should be enforcing small URLs to all users, for SEO.

Note: there is a high likelihood that this script will give errors on very big web sites and old web sites (asking for a Big Letter CSS file, and receving a small one). Try to use it on new web sites, where you can instantly see if anything goes wrong.

You also have the option of implementing rel=canonical, which give you 70-80% of the results of the current solution

Generally, WordPress, by default, does a pretty good job at SEO. Its default settings are pretty OK. With a few plugins (backup / a plugin for sitemap.xml generator / some basic tweaking in the theme settings for meta title / a basic knowledge on how to add the images / a cache plugin) you can go from good to great.

Anyhow, at the current setting – change from big to small letters, WordPress does nothing.

What you should do is edit your .htaccess file and add in it the following code:

RewriteEngine On
RewriteBase /

# 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
RewriteRule ^([^B]*)B(.*)$ $1b$2
RewriteRule ^([^C]*)C(.*)$ $1c$2
RewriteRule ^([^D]*)D(.*)$ $1d$2
RewriteRule ^([^E]*)E(.*)$ $1e$2
RewriteRule ^([^F]*)F(.*)$ $1f$2
RewriteRule ^([^G]*)G(.*)$ $1g$2
RewriteRule ^([^H]*)H(.*)$ $1h$2
RewriteRule ^([^I]*)I(.*)$ $1i$2
RewriteRule ^([^J]*)J(.*)$ $1j$2
RewriteRule ^([^K]*)K(.*)$ $1k$2
RewriteRule ^([^L]*)L(.*)$ $1l$2
RewriteRule ^([^M]*)M(.*)$ $1m$2
RewriteRule ^([^N]*)N(.*)$ $1n$2
RewriteRule ^([^O]*)O(.*)$ $1o$2
RewriteRule ^([^P]*)P(.*)$ $1p$2
RewriteRule ^([^Q]*)Q(.*)$ $1q$2
RewriteRule ^([^R]*)R(.*)$ $1r$2
RewriteRule ^([^S]*)S(.*)$ $1s$2
RewriteRule ^([^T]*)T(.*)$ $1t$2
RewriteRule ^([^U]*)U(.*)$ $1u$2
RewriteRule ^([^V]*)V(.*)$ $1v$2
RewriteRule ^([^W]*)W(.*)$ $1w$2
RewriteRule ^([^X]*)X(.*)$ $1x$2
RewriteRule ^([^Y]*)Y(.*)$ $1y$2
RewriteRule ^([^Z]*)Z(.*)$ $1z$2

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

RewriteCond %{ENV:HASCAPS} TRUE
RewriteRule ^/?(.*) /$1 [R=301,L]

I got the hint via: Htaccess Rewrite to redirect Uppercase to Lowercase ».

Kristina Alexanderson - The letter J, https://flic.kr/p/bAoRak
Kristina Alexanderson – The letter J, https://flic.kr/p/bAoRak

Also see: rel=”canonical”-URL for WordPress Theme – WP Engineer

Share on WhatsAppLinks giving error?

Lasă un comentariu

Rules for commenters »

Puteți folosi Gravatar pentru a adăuga avatar (imagine comentarii).