index.php重定向的正则表达式(但有点复杂!)

index.php重定向的正则表达式(但有点复杂!),php,.htaccess,Php,.htaccess,你好,谢谢你看这个。我有一个问题,我需要重定向: www.thisdomain.com/index.php 致: www.thisdomain.com/ 但是 由于我有两个index.php文件,这一点变得复杂了。这里有一个: www.thisdomain.com/index.php 这里有一个: www.thisdomain.com/a_forum/a_forum_submission/index.php 因此,我将使用的普通301重定向是: RewriteCond %{THE_REQUEST

你好,谢谢你看这个。我有一个问题,我需要重定向: www.thisdomain.com/index.php 致: www.thisdomain.com/

但是

由于我有两个index.php文件,这一点变得复杂了。这里有一个: www.thisdomain.com/index.php 这里有一个: www.thisdomain.com/a_forum/a_forum_submission/index.php

因此,我将使用的普通301重定向是:

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.thisdomain.co.uk/$1 [R=301,L]
问题是,这也会将较低级别的index.php重定向到不需要的路由

因此,我想要实现的是将www.thisdomain.com/index.php重定向到根目录,但不将www.thisdomain.com/a_forum/a_forum_submission/index.php重定向到根目录

如果你能帮我,我将非常感激。我已经尝试了我所知道的一切,但我的正则表达式知识让我失望

再次感谢


D

取出通配符匹配表达式
(.*)


你应该做你想做的事。有了它,您甚至可能不需要重写Cond。我认为解决这个问题的更简单方法是在www.thisdomain.com/a_forum/a_forum\u submission/中创建一个.htaccess文件,覆盖重写Cond或停用重写模块。

只需执行以下操作:

RewriteRule ^index\.php http://www.thisdomain.co.uk/ [R=301,L]
不过,不需要重写条件

祝你今天愉快。

试试看

 Redirect 301 /index.php http://www.thisdomain.com

.htaccess
文件很烂。每次提供文件时,webserveer都必须解析它们。我同意,但很多Web服务器提供商都不给您这个选项。
RewriteRule^index\.php(.*)http://www.thisdomain.co.uk/$1[R=301,L]
重写规则^index\.phphttp://www.thisdomain.co.uk/ [R=301,L,QSA]
可以更好地传递url字符串。
 Redirect 301 /index.php http://www.thisdomain.com
RewriteRule ^index\.php(.*) http://www.thisdomain.co.uk/$1 [R=301,L]