davelowe85
davelowe85

Reputation: 1109

Redirect page to homepage using htaccess

I have a rewrite rule setup which works well:

RewriteRule ^circuit/([a-zA-Z0-9-]+)/([^/]*)$ /circuit.php?id=$2 [L]

What I would like though, is if someone went to http://www.example.com/circuit.php that it redirects to the homepage, but if someone went to http://www.example.com/circuit/some-circuit/3 for it still to work.

I've tried simply using this approach:

Redirect /circuit.php http://www.example.com/

And this works in redirecting circuit.php but it also stops the dynamic pages working, I'm sure there is a simple answer for this..

Upvotes: 1

Views: 45

Answers (1)

anubhava
anubhava

Reputation: 785098

This should work:

RewriteCond %{THE_REQUEST} /circuit\.php [NC]
RewriteRule ^ / [L,R=302]

RewriteRule ^circuit/([a-zA-Z0-9-]+)/([^/]*)$ /circuit.php?id=$2 [L,QSA,NC]

Upvotes: 1

Related Questions