简体   繁体   English

使用htaccess将页面重定向到首页

[英]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. 我要的是,如果有人访问了http://www.example.com/circuit.php ,它将重定向到主页,但是如果有人访问了http://www.example.com/circuit/some-,电路/ 3 ,它仍然可以工作。

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.. 这在重定向circuit.php中有效,但是它也停止了动态页面的工作,我敢肯定有一个简单的答案。

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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