【发布时间】:2017-01-06 15:32:28
【问题描述】:
我想要做的是如果 url 有 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 到 / 的重定向。
【问题讨论】:
-
我只是想澄清一下——所以如果有任何目录和/或文件,您希望它重定向到 404 错误页面吗?
-
@thickguru 给定 URL
/index.php/anything- "anything" 是附加的路径信息,它与目录或文件无关。 -
@DocRoot 如果它类似于 1) /index.php/string 2) /index.php/directory 3) /index.php/pathwhichdoesnotexists 那么它应该重定向到 /error-404跨度>
标签: php regex apache .htaccess redirect