Hi all,

newbie question here...

Is there a simple solution to rewrite my urls with capital letters to all lowercase?

i.e.

to

I'm building a directory and the url's are rewritten but keep the uppercase letters right now. I would like to change that to all lowercase.

can this be done with a mod rewrite rule? what should I add to my .htaccess file to make it work?

Thanks
DD

Dani AI

Generated

Quick summary and practical options for : there are three realistic ways to force lowercase URLs — do it at the webserver (best control and performance), use a server module that tolerates case differences, or perform the lowercase + redirect inside your application. Which one to pick depends on whether you can edit the main Apache config (httpd.conf / virtual host) or only have .htaccess on a shared host. ’s idea of a map-based rewrite is the right concept for server-level conversion, but that kind of map must be declared in server/virtual-host context (putting it in .htaccess causes a 500). (httpd.apache.org)

If you cannot change the server config, consider a module that tolerates capitalization mismatches instead of wholesale rewrite — Apache’s mod_speling can match filenames regardless of case (with performance and security caveats: it scans the directory and can accidentally match sensitive files). That can be handy for forgiving user-typed URLs without changing filenames. (httpd.apache.org)

If neither server-level map nor mod_speling is available, do the normalization at application entry (before your app routes the request). Example (PHP) — detect when the path contains uppercase letters, build the lowercase target (preserve query string), and issue a 301 permanent redirect. This avoids depending on host-level features and prevents duplicate-content variants; remember to guard against redirect loops and to encode/decode safely when your URLs contain percent-encoded characters.

SEO and filesystem notes: search engines won’t “penalize” case itself, but inconsistent casing creates duplicate URLs and indexation noise — use server 301 redirects or rel=canonical to consolidate. For quick verification test with curl -I or check your server error_log for messages like “RewriteMap not allowed here.” Also be aware that, by standard, scheme and host are case-insensitive but the path is treated as case-sensitive by default (so a lowercase redirect can 404 if the filesystem or application expects the original case). (developers.google.com)

Acknowledgement: and pointed toward server-map solutions and the .htaccess gotcha; ’s usability point is right — consistency matters more than case for SEO.

Recommended Answers

All 10 Replies

RewriteEngine on 
RewriteMap upper2lower int:tolower 
RewriteRule ^/(.*)$ /${upper2lower:$1}

Amnot sure if it will work or not. You can read the full post here...
http://balajin.net/blog/archives/2005/10/07/using_mod_rewrite_to_convert_u.html

I am getting a 500 error when I add this to my .htaccess file

# Protect files
<Files ~ "^(.*)\.(inc|inc\.php|tpl|sql)$">
  Order deny,allow
  Deny from all
</Files>

# Protect directories
<Files ~ "^(backup|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$">
  Order deny,allow
  Deny from all
</Files>

# Disable directory browsing
Options -Indexes

# Follow symbolic links in this directory
Options +FollowSymLinks

# Override PHP settings that cannot be changed at runtime
# (If your server supports PHP settings via htaccess you can comment following two lines off)
# php_value register_globals   0
# php_value session.auto_start 0

# Customized error messages
# ( If you are running in a subfolder please add it, example: "directory/index.php?httpstatus=404" )
ErrorDocument 404 index.php?httpstatus=404

# Set the default handler
DirectoryIndex index.php

# URL rewrite rules
<IfModule mod_rewrite.c>
   
   RewriteEngine On
   
   ## Details Link Page Rewrite##
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule (.*)fishing/link-(.*).html$ detail.php [QSA,NC]

   ## Pagination Rewrite
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule (.*)page-(\d+)\.html$  $1/?p=$2 [PT,NC]

   ## Category redirect
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule ^(.*)$ index.php [QSA,L]

</IfModule>

any idea where and how I should add this?

case is not a factor considered by search engines in rating websites. Its more of a site usibility issue than a SEO one.

Hi all,

newbie question here...

Is there a simple solution to rewrite my urls with capital letters to all lowercase?

i.e.

to

I'm building a directory and the url's are rewritten but keep the uppercase letters right now. I would like to change that to all lowercase.

can this be done with a mod rewrite rule? what should I add to my .htaccess file to make it work?

Thanks
DD

Hi,

Why you want this to be done? For SEs? :!:

Aside from the SEs, my guess would be to accomidate for typos. Or ... because he used to use capital letters and now he wants to use all lowercase because it's easier to type in and such, and he doesn't want the old URLs to be broken.

Aside from the SEs, my guess would be to accomidate for typos. Or ... because he used to use capital letters and now he wants to use all lowercase because it's easier to type in and such, and he doesn't want the old URLs to be broken.

Hi,

Both and http://www.asdf.com/asd.php is equal :) So no borken URLs :mrgreen:

RewriteEngine on 
RewriteMap upper2lower int:tolower 
RewriteRule ^/(.*)$ /${upper2lower:$1}

Amnot sure if it will work or not. You can read the full post here...
http://balajin.net/blog/archives/2005/10/07/using_mod_rewrite_to_convert_u.html

You are almost correct, but you have to place the code in httpd.conf and not in the .htaccess (Internal server error will occure)

You can place the code as follows in httpd.conf

<virtualhost.....
<bunch of host stuff>

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]

</VirtualHost>

Please check

You are almost correct, but you have to place the code in httpd.conf and not in the .htaccess (Internal server error will occure)

You can place the code as follows in httpd.conf

<virtualhost.....
<bunch of host stuff>

RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]

</VirtualHost>

Please check

Thanks, this helped greatly where mod_speling would not.

I think it's not effective to site

Just a stupid infact a simple question here.

why do you exactly want to change your letters from upper case to lower case ? is there any SEO benefit or what ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.