Nick
Nick

Reputation: 3965

Using wildcards in a htaccess redirect?

My girlfriend wants to disable her blog and re-direct all traffic back to her site.

I've added this into the root's htaccess file:

RedirectMatch 301 ^/blog/$ http://www.site.co.uk

Which re-directs http://www.site.co.uk/blog without any problems, however any blog posts (ie http://www.site.co.uk/blog/post-url) do still load up and do not re-direct.

I've tried the following and unfortunately I cannot get the subpages from /blog/ to re-direct:

# Attempt 1
RedirectMatch 301 ^/blog/(.*)$ http://www.site.co.uk

#Attempt 2
RedirectMatch 301 ^/blog/*$ http://www.site.co.uk

Here is the .htaccess file at site.co.uk (Opencart) and here is the .htaccess file at site.co.uk/blog/ (Wordpress)

I have tried clearing both htaccess files so the only remaining line is RedirectMatch 301 ^/blog/$ http://www.site.co.uk and unfortunately it still doesn't re-direct anything above the /blog/ level.

Any ideas as to what I'm doing wrong please?

Thank you :)

Upvotes: 0

Views: 73

Answers (1)

meberhard
meberhard

Reputation: 1845

Is there a certain reason you want to use RedirectMatch? A simple Redirect 301 should do the job:

RewriteEngine on
Redirect 301 /blog http://example.com

By the way, before you use 301 (moved permanently), use 302 (moved temporarily) instead. Like this you are able to test and your browser and the browsers of other users will not cache wrongly implemented redirects. In order to do so, just remove the 301. When everything is working, add it again:

RewriteEngine on
Redirect /blog http://example.com

If the redirect doesn't work, try to clean your browser cache. It is possible that some old rule is cached.

Upvotes: 1

Related Questions