[英]How to redirect if the url have index.php/somefileOrsomedirectory
What do i want to do is if the url have www.example.com/index.php/anything
then it should throw the user to www.example.com/error-404
Here is my current expressions in my htaccess file. 我想做的是,如果该网址包含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/
Thanks in advance. 提前致谢。 Please suggest/edit my question if i have not asked the question in correct way. 如果我没有以正确的方式提出问题,请提出/编辑我的问题。
EDIT I don't want to loose the /index.php
to /
redirection. 编辑我不想将/index.php
放到/
重定向。
I think the following should do what you require. 我认为以下应满足您的要求。 The dot is any character and the + means one or more times. 点是任何字符,而+表示一次或多次。 This would require the forward slash to be there 这将需要使用正斜杠
RewriteRule ^index\.php/(.+)$ error-404 [L]
EDIT: Thanks @DocRoot, updated accordingly 编辑:谢谢@DocRoot,相应地更新
www.example.com/index.php/anything
/anything
here is additional path information (after the name of a physical file). /anything
是其他路径信息 (在物理文件名之后)。 You can use the AcceptPathInfo
directive to specifically disable this "feature": 您可以使用AcceptPathInfo
指令专门禁用此“功能”:
AcceptPathInfo Off
In which case all URLs containing additional path info will automatically trigger a 404. However, the URLs can still be routed using mod_rewrite, which is probably what's happening here. 在这种情况下,所有包含附加路径信息的URL都会自动触发404。但是,仍然可以使用mod_rewrite来路由这些URL,这可能就是这里发生的情况。
You will still need to implement a mod_rewrite redirect as mentioned in the datascript's answer. 您仍然需要实现data_script答案中提到的mod_rewrite重定向。 Or try something like the following, before your existing directives: 或在现有指令之前尝试以下类似方法:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php/ /error-404 [R=302,L]
The check against REDIRECT_STATUS
is to avoid a rewrite loop, since your front controller appears to use path info to route the request. 对REDIRECT_STATUS
的检查是为了避免重写循环,因为您的前端控制器似乎使用路径信息来路由请求。
Change this to a 301
if this is intended to be permanent, once you have confirmed it's working OK. 如果您打算永久使用,请将其更改为301
,一旦确认它可以正常运行。
However, it would be preferable if this was implemented as a proper Apache error document. 但是,最好将其实现为正确的Apache错误文档。 For example: 例如:
ErrorDocument /error-404.php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php/ - [R=404,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.