我的网站使用以下格式的链接:
http://www.website.com/section1/index.php
http://www.website.com/section2/index.php
http://www.website.com/section3/index.php
http://www.website.com/section1/section4/index.php
我试图通过使用以下.htaccess指令来删除最后一部分“index.php”:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule (.*) http://www.google.com [R=301,NC,L]
当然,www.google.com仅用于测试目的,但下面的示例不起作用。这有什么问题?问题的第二部分是如果我想重写为http://www.website.com/section1,我该如何替换www.google.com?
谢谢!
答案 0 :(得分:1)
由于你的正则表达式不正确,它无效。 RewriteCond %{REQUEST_URI} ^/index\.php$
期待%{REQUEST_URI}
为/index.php
,但您有/section1/index.php
。
正确的版本将是:
RewriteEngine on
RewriteCond %{REQUEST_URI} /index\.php$
RewriteRule (.*) http://www.google.com [R=301,NC,L]
甚至:
RewriteEngine on
RewriteRule /index\.php$ http://www.google.com [R=301,NC,L]