简体   繁体   English

如果在文件扩展名后输入尾部斜杠,则返回404

[英]Return a 404 if trailing slash is entered after file extension

I am using AddType application/x-httpd-php .htm .html on static .html pages to serve as PHP in .htaccess file. 我在静态.html页面上使用AddType application/x-httpd-php .htm .html.htaccess文件中用作PHP。

The problem is when someone enters a trailing slash after the .html file extension, the URL can extend to anything causing huge number of junk/duplicate pages. 问题是当某人在.html文件扩展名后输入尾部斜杠时,URL可以扩展到导致大量垃圾/重复页面的任何内容。

eg, www.example.com/file.html would serve the same page as www.example.com/file.html/file.html or www.example.com/file.html/anything-here-bla-bla 例如, www.example.com/file.html将提供与www.example.com/file.html/file.htmlwww.example.com/file.html/anything-here-bla-bla相同的页面

If someone enters www.example.com/file.html/anything , for example, I want to redirect to a 404 page. 例如,如果有人输入www.example.com/file.html/anything ,我想重定向到404页面。

Just found the solution myself. 我自己找到了解决方案。 Here is what will do the desired. 以下是将要做的事情。

RewriteEngine On RewriteCond %{THE_REQUEST} /([^.]+).html/ [NC] RewriteRule ^(.*)$ /404.shtml [NC,R,L] RewriteEngine On RewriteCond%{THE_REQUEST} /([^.]+).html/ [NC] RewriteRule ^(。*)$ /404.shtml [NC,R,L]

This will redirect visitors/googlebot to 404.shtml when a trailing slash is added after the file extension (.html) in this case. 在这种情况下,当在文件扩展名(.html)之后添加尾部斜杠时,这会将visitor / googlebot重定向到404.shtml。

Hope this will help others. 希望这会有助于他人。

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

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