redirect URL to lowercase

Using the realurl extension TYPO3 generate human-readable URL. If the visitor visits the page using uppercase of the URL, TYPO3 can generate the page (HTTP 200). if a search bot (Google) found this URL and indexed it, Google will declare the page as “double content” and punishes your page rank. How do we deal with this?

using the RewriteMap we can rewrite all uppercase to the lower case.

1
2
RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*$) ${lc:$1} [R=301,L]

but there are another problems: files and GET parameter.

Files are easier to handle. Using RewriteCond we can check if the requested URL points to a file.

1
RewriteCond %{REQUEST_FILENAME} !-f

for GET parameter, we just change the regular expression to points everything between 2 slahes (/…/)

1
RewriteRule (/.*?[A-Z]+.*/$) ${lc:$1} [R=301,L]

so in the end we have following rewrite rule

1
2
3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteMap lc int:tolower
RewriteRule (/.*?[A-Z]+.*/$) ${lc:$1} [R=301,L]

PS: RewriteMap can only be set in server config or vhost. So, putting this in htaccess won’t change anything 🙂

2 thoughts on “redirect URL to lowercase”

Leave a Reply

Your email address will not be published. Required fields are marked *