繁体   English   中英

如何使用htaccess文件将“ http://www.example.com/pathquery-string=something”之类的网址重定向到错误页面

[英]How to redirect url like “http://www.example.com/pathquery-string=something” to error page using htaccess file

如何使用htaccess文件将“ http://www.example.com/pathstring=something ”之类的网址重定向到错误页面。 http://www.example.com/path ”这是url的一部分,“ string = something”是查询字符串的一部分。 如果有人错过了“?” 在查询字符串中,页面应重定向到错误页面。
这是我的htaccess代码

 RewriteEngine on  
  RewriteCond %{REQUEST_FILENAME} !-f  
  RewriteCond %{REQUEST_FILENAME} !-d  
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]  

您可以使用它:

RewriteRule ^path([A-Za-z0-9-]+)$ /error-page.html [R=301,L]

如果没有“?” path之后,它将重定向到错误页面

哦,好吧, http://www.example.com/pathstring=something不会重定向到具有以下内容的重写规则: http : //www.example.com/path ?string =something

但是,如果http://www.example.com/pathstring=something不是有效的URL,并且.htaccess中没有该路径的重写规则,则可以将所有未找到的页面重定向到404页面。 添加到您的.htaccess

RewriteEngine On 
ErrorDocument 404 /my-404-page.html 

暂无
暂无

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

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