Case-insensitive htaccess 301

developdaly picture developdaly · Apr 6, 2013 · Viewed 11.1k times · Source

I have about 300 redirects in the following format

Redirect 301 /post/My-Blog-Post.aspx https://www.example.com/blog/a-new-post/

That works great except the redirects are case sensitive and going to /post/my-blog-post.aspx doesn't redirect.

There isn't a pattern for the old URL to new URL so this would likely have to be a flag for every redirect.

How can I get the URL to redirect no matter the case?

Answer

Jon Lin picture Jon Lin · Apr 6, 2013

Don't think there's a way to make the Redirect directive (part of mod_alias) case insensitive, but there's a mod_rewrite flag that you can use. You'll need to change all of your redirects from this:

 Redirect 301 /post/My-Blog-Post.aspx https://www.example.com/blog/a-new-post/

to:

 RewriteRule ^/?post/My-Blog-Post.aspx$ https://www.example.com/blog/a-new-post/ [L,R=301,NC]

Note the NC flag, meaning "no case". This will match any URI that looks like /post/my-blog-post.aspx and ignores case, and redirects it to https://www.example.com/blog/a-new-post/.