Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect without the path

I have the following htaccess rule:

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

On an old blog at http://blog.example.co.uk/ that should be redirecting ALL urls from this old blog to the new one.

However if I have anything in the path: e.g. http://blog.example.co.uk/2015/test-post then it redirects to http://www.example.co.uk/blog/2015/test-post

How do I make it so that it doesn't keep the path and just redirects to the domain.

like image 960
Cameron Avatar asked May 11 '15 10:05

Cameron


1 Answers

You need to use RedirectMatch for that:

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

Make sure to test this in a new browser.

Or if you want to strip off any existing query string also then use mod_rewrite:

RewriteEngine On
RewriteRule ^ http://www.example.co.uk/blog/? [L,R=301]
like image 177
anubhava Avatar answered Nov 15 '22 19:11

anubhava