10

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?

serraosays
  • 7,163
  • 3
  • 35
  • 60
developdaly
  • 1,373
  • 3
  • 16
  • 26

2 Answers2

11

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

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • No dice -- same result. – developdaly Apr 12 '13 at 13:37
  • Adding the NC flag worked on a couple of different sites for me, one server running Apache 2.2 and another on 2.4. Check Apache's documentation, it is consistent with Jon Lin's answer: https://httpd.apache.org/docs/current/rewrite/flags.html#flag_nc – serraosays Nov 14 '13 at 16:32
1

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]