繁体   English   中英

如何重定向网址是否具有index.php / somefileOrsomedirectory

[英]How to redirect if the url have index.php/somefileOrsomedirectory

我想做的是,如果该网址包含www.example.com/index.php/anything它将把用户带到www.example.com/error-404这是我htaccess文件中的当前表达式。

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule (.*)$ http://www.example.com/$1 [L,R=301]
Redirect 301 /online-features/key-anywhere-web-based-system http://www.example.com/online-features
Redirect 301 /home http://www.example.com/

提前致谢。 如果我没有以正确的方式提出问题,请提出/编辑我的问题。

编辑我不想将/index.php放到/重定向。

我认为以下应满足您的要求。 点是任何字符,而+表示一次或多次。 这将需要使用正斜杠

RewriteRule ^index\.php/(.+)$ error-404 [L]

编辑:谢谢@DocRoot,相应地更新

www.example.com/index.php/anything

/anything是其他路径信息 (在物理文件名之后)。 您可以使用AcceptPathInfo指令专门禁用此“功能”:

AcceptPathInfo Off

在这种情况下,所有包含附加路径信息的URL都会自动触发404。但是,仍然可以使用mod_rewrite来路由这些URL,这可能就是这里发生的情况。

您仍然需要实现data_script答案中提到的mod_rewrite重定向。 或在现有指令之前尝试以下类似方法:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php/ /error-404 [R=302,L]

REDIRECT_STATUS的检查是为了避免重写循环,因为您的前端控制器似乎使用路径信息来路由请求。

如果您打算永久使用,请将其更改为301 ,一旦确认它可以正常运行。

但是,最好将其实现为正确的Apache错误文档。 例如:

ErrorDocument /error-404.php

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php/ - [R=404,L]

暂无
暂无

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

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