简体   繁体   English

.htacess重写以截断具有常见错误的链接?

[英].htacess rewrite to truncate links with common mistakes?

Everyone who have tried to search through error_log files from large websites got lots of links like these bellow due to people who have screwd up some html in third part sites or blogs... 试图从大型网站中搜索error_log文件的每个人都有很多这样的链接,这是由于有人在第三方网站或博客中弄乱了一些html ...

File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html'http://...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html http://...
File does not exist: /var/www/vhosts/mydomain.com/httpdocs/materias/137.html/mydomain...

The problem is some extra chars after the .html... 问题是.html之后有一些额外的字符。

Its easy to guess the correct url in each case... we just have to truncate the url after the ".html". 在每种情况下,很容易猜出正确的网址...我们只需要在“ .html”之后截断网址。

Is it possible with .htaccess to rewrite these problematic urls to the correct syntax? .htaccess是否可以将这些有问题的url重写为正确的语法?

Just eliminating everything after the . 只是消除了之后的一切。

html? HTML? And avoiding messing up with url queries in dynamic urls? 并避免弄乱动态网址中的网址查询?

Here's what I would like to do ... 这就是我想做的...

Replace ".html " with ".html#" ".html "替换为".html#"

Replace ".html'" with ".html#" ".html'"替换为".html#"

Replace ".html/" with ".html#" ".html/"替换为".html#"

As everything after the # will be just ignored... #之后的所有内容都将被忽略...

Any simple way to do that with .htaccess? 用.htaccess做到这一点的任何简单方法?

只需使用正则表达式:

RewriteRule ^(.*)\.html(.*)$    $1.html

RedirectMatch规则应起作用:

RedirectMatch 301 ^(.+?\.html).+$ $1

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

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