简体   繁体   中英

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..

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM