Htaccess redirect without path

I have the following htaccess rule:

Redirect 301 / http://www.example.co.uk/blog/ 

In the old blog at http://blog.example.co.uk/ , which should redirect ALL URLs from this old blog to the new one.

However, if I have something along the way: for example. http://blog.example.co.uk/2015/test-post , then it is redirected to http://www.example.co.uk/blog/2015/test-post

How to make it not save the path and just redirect the domain.

+5
source share
1 answer

For this you need to use RedirectMatch :

 RedirectMatch 301 ^ http://www.example.co.uk/blog/ 

Be sure to check this out in the new browser.

Or, if you want to delete any existing query string, then use mod_rewrite :

 RewriteEngine On RewriteRule ^ http://www.example.co.uk/blog/? [L,R=301] 
+6
source

All Articles