Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case-insensitive htaccess 301 [closed]

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?

like image 759
developdaly Avatar asked Apr 06 '13 14:04

developdaly


2 Answers

However, if you want to make "My-Blog-Post" a variable of "a-new-post", I mean if you want /post/My-Blog-Post.aspx to be redirected into /blog/a-new-post/ either /post/this.aspx into /blog/this/ or /post/that.aspx into /blog/that/ or even /post/anything.aspx into /blog/anything/, you can try to use this code in you .htaccess hidden file:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^post/([a-z0-9-_]+).aspx$ /blog/$1/ [R=301,NC]
like image 41
5ervant - techintel.github.io Avatar answered Oct 12 '22 05:10

5ervant - techintel.github.io


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/.

like image 94
Jon Lin Avatar answered Oct 12 '22 05:10

Jon Lin