扩展后删除不需要的字符 [英] Removing unwanted characters after extension
本文介绍了扩展后删除不需要的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些通过cgi进行的查询调用的页面。
I have pages that are called via a query strung from a cgi.
xyz.cgi?page=abc.html
我遇到的问题是,我收到了对确实存在的页面的机器人请求,但该请求具有 .html
之后的字符,结果是404。
The problem that I have is that I get bot requests for pages that do exist, but the request has characters after the .html
and the result is a 404.
.htaccess
删除 .html
扩展名之后的所有内容?
Is there a way in .htaccess
to strip off everything after the .html
extension?
推荐答案
您可以使用以下规则在html扩展名后删除字符:
You can use the following rule to remove chars after the html extension :
RewriteRule ^(.+\.html).+$ /$1 [L,R]
这将重定向
/foo.htmlchars
至
/foo.html
或
RedirectMatch ^/(.+\.html).+$ /$1
编辑:
重定向 /xyz.cgi?page=foo.html字符到 /xyz.cgi?page=foo.html ,您可以使用以下命令:
To redirect /xyz.cgi?page=foo.htmlchars to /xyz.cgi?page=foo.html you may using the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} /xyz\.cgi\?page=(.+\.html).+\sHTTP [NC]
RewriteRule ^ /xyz.cgi?page=%1 [L,R]
这篇关于扩展后删除不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文