<p>Depending on how your server is configured, this may be a non-issue. I just checked several sites, and they all work fine with mixed-case URLs.</p>

<p>If that's not the case with your site, you'll need to implement a simple plugin, which checks the URL, converts it to lowercase, and redirects the visitor (if required).</p>

<p>Hopefully it goes without saying that it would be <em>much</em> better to do this in your <code>.htaccess</code> or <code>httpd.conf</code>.</p>

<p>Caveats dispensed with, here's an example plugin.</p>

<pre><code>&lt;?php namespace Craft;

class PoorMansRedirectPlugin extends BasePlugin
{
    // Standard plugin methods omitted for brevity.


    /**
     * Runs before *every* request.
     */
    public function init()
    {
        $path = craft()-&gt;request-&gt;getPath();
        $lowerPath = strtolower($path);

        // If the current path is not lowercased, redirect.
        if ($path !== $lowerPath) {
            $url = UrlHelper::getUrl($lowerPath);
            craft()-&gt;request-&gt;redirect($url);
        }
    }
}
</code></pre>

<p>Just to be clear, this is a really bare-bones solution.</p>

<p>It doesn't make any distinction between site URLs and admin URLs, doesn't account for query strings, will break POST requests, and a lot more besides.</p>

<p>As such it is in no way production ready, and would require quite a bit of additional work to account for all of these edge (and not so edge) cases. See my previous note regarding <code>.htaccess</code> being vastly preferable.</p>

CC BY-SA 3.0
2017-04-17T00:39:37.463Z
Thank you very much for the clarification. On our server, the case needs to be exact. I never thought about messing up POSTs, and it turns out the .htaccess fix for it, though long, isn't noticibly slow. So .htaccess it is!
kr37
CC BY-SA 3.0
2017-04-16T17:58:26.820Z
2017-04-17T04:02:01.250Z
2017-04-17T04:02:01.250Z
Stephen Lewis
<p>This is the .htaccess which is working for me now. From this <a href="http://www.askapache.com/htaccess/rewrite-uppercase-lowercase/" rel="nofollow noreferrer">site</a></p>

<p><strong>Htaccess to Redirect Uppercase to Lowercase</strong> </p>

<p>This should go at the very top of your .htaccess file. At least it should go above ANY other RewriteRules. That is because this uses a loop, until there are no more uppercase characters to convert, it will keep starting at the first HASCAPS:TRUE RewriteRule. Oh, and this is actually really quick and isn't gonna slow down anything.</p>

<pre><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]
</code></pre>

CC BY-SA 3.0
2017-04-17T00:44:02.687Z
2017-04-17T00:44:02.687Z
kr37
<p>I think this is normally done with .htaccess or httpd.conf, but it's a bit cumbersome on shared hosting, and it seems like a simple trick for a CMS...</p>

<p>Can Craft convert requested URLs to lowercase? So if the slug for the page is /meditate, but someone types in /Meditate that Craft delivers /meditate page?</p>

<p>I don't quite understand how one uses customAsciiCharMappings -- it seems unrelated to this.</p>

<url>
Can Craft convert requested url to lowercase?
# Can Craft convert requested url to lowercase?

(Asked by: username_0 on 2017-04-16)

I think this is normally done with .htaccess or httpd.conf, but it's a bit cumbersome on shared hosting, and it seems like a simple trick for a CMS...

Can Craft convert requested URLs to lowercase? So if the slug for the page is /meditate, but someone types in /Meditate that Craft delivers /meditate page?

I don't quite understand how one uses customAsciiCharMappings -- it seems unrelated to this.

**Tags:** url


---

## 2 answers

### Answer by username_1 on 2017-04-16. Score: 3 | Accepted answer

Depending on how your server is configured, this may be a non-issue. I just checked several sites, and they all work fine with mixed-case URLs.
If that's not the case with your site, you'll need to implement a simple plugin, which checks the URL, converts it to lowercase, and redirects the visitor (if required).
Hopefully it goes without saying that it would be much better to do this in your .htaccess or httpd.conf.
Caveats dispensed with, here's an example plugin.
request->getPath();
        $lowerPath = strtolower($path);

        // If the current path is not lowercased, redirect.
        if ($path !== $lowerPath) {
            $url = UrlHelper::getUrl($lowerPath);
            craft()->request->redirect($url);
        }
    }
}

Just to be clear, this is a really bare-bones solution.
It doesn't make any distinction between site URLs and admin URLs, doesn't account for query strings, will break POST requests, and a lot more besides.
As such it is in no way production ready, and would require quite a bit of additional work to account for all of these edge (and not so edge) cases. See my previous note regarding .htaccess being vastly preferable.

> **Comments:**
> **username_0**: Thank you very much for the clarification. On our server, the case needs to be exact. I never thought about messing up POSTs, and it turns out the .htaccess fix for it, though long, isn't noticibly slow. So .htaccess it is!  

---

### Answer by username_0 on 2017-04-17. Score: 1

This is the .htaccess which is working for me now. From this site
Htaccess to Redirect Uppercase to Lowercase 
This should go at the very top of your .htaccess file. At least it should go above ANY other RewriteRules. That is because this uses a loop, until there are no more uppercase characters to convert, it will keep starting at the first HASCAPS:TRUE RewriteRule. Oh, and this is actually really quick and isn't gonna slow down anything.
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]


---

