0

is it possible to keep certain parts of an URL and to rewrite the rest? With a .htaccess 301 redirect.

In my example I would like to rewrite URLs from this format

http://blog.example.com/post-name

to this one

http://example.com/2014/post-name

So far the year (2014) can be static because only a couple of links would be affected.

Thanks!

Øle Bjarnstroem
  • 305
  • 4
  • 11

1 Answers1

2

Keep in mind that this'll redirect every request to blog.example.com since it's just capturing anything after the slash and redirecting, so please clarify if you need it to be smarter, but..

RedirectMatch 301 ^/(.*)$ http://example.com/2014/$1
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • To clarify for anyone else: I pointed the .blog subdomain to an empty folder in which I put a .htaccess file with the above line. Works perfectly. Thanks. – Øle Bjarnstroem Nov 08 '14 at 21:06