Forum Moderators: phranque

Message Too Old, No Replies

Lowercase URLS

causing 500 errors

         

delboy1978uk

1:38 pm on Aug 15, 2012 (gmt 0)

10+ Year Member



Hi everyone!
I have swapped an old site on a cPanel host for a new one written in Zend Framework.

And as always, sods law kicked in and the job spec changed. Since the old sites google results were quite good, he wants the urls to be the same.

But if i browse to site.com/Contact instead of site.com/contact it doesn't work!

My current htaccess is like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|gif|jpg|png|css|txt)$ index.php


which is a typical zend framework .htaccess
I notice the line with NC means no case, but the dash means do not rewrite!
It is a dedicated server so i can access the apache configs

Any ideas?

g1smd

7:02 pm on Aug 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here, the
NC
flag has no effect.

The
(.*)
matches all requests.

The
NC
flag is used when the RegEx pattern is
^page$
and you want to accept any case request. Without the
NC
flag in place, only
example.com/page
would match, but with the
NC
flag added, requests for
example.com/Page
and
example.com/pAgE
would also match.

However, you should not normally use the
NC
flag with a rewrite that directly serves content, use it only with a redirect. You should not allow multiple URLs to access the same content, and that's what the
NC
flag would do when used with a rewrite that serves content.

The solution to your problem is fairly simple. When a request with any upper case characters is received, rewrite (that's rewrite not redirect) the request to a PHP script that uses
strtolower()
to deduce the new URL and the
HEADER
directive to issue a 301 redirect to the new URL. This is now safe, content is now only served at lower case URLs, and the redirect retains traffic asking for upper case URLs.