Cameron
Cameron

Reputation: 28783

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.

Upvotes: 13

Views: 7063

Answers (1)

anubhava
anubhava

Reputation: 784998

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]

Upvotes: 21

Related Questions