Apache - mod

    技术2022-05-11  105

    Apache - mod_rewrite - RewriteRule中的正则表达式需要考虑是否要对.转义(匹配任意字符还是仅匹配.字符)

    [例1]

    rewritecond %{HTTP_HOST} ^www.[^.]+.host.com$

    不仅匹配

    www.user.host.com

    也匹配

    wwwxuser.host.com

    所以应该改成

    rewritecond %{HTTP_HOST} ^www/.[^.]+/.host/.com$

    这样就不会匹配

    wwwxuser.host.com

    [例2]

    这是一个反盗链的应用

    RewriteCond %{HTTP_REFERER} !^http://blog .csdn .net/hu_zhenghui$

    注意其中的!表示不匹配时条件才成立 下面的链接不被认为是盗链

    http://blog.csdn.net/hu_zhenghui

    下面的链接也不被认为是盗链

    http://blogacsdn.net/hu_zhenghui

    所以应该修改成

    RewriteCond %{HTTP_REFERER} !^http://blog /.csdn /.net/hu_zhenghui$

    [apache关键词]

    apache

    [mod_rewrite模块关键词]

    httxt2dbm mod_rewrite ornext RewriteBase RewriteCond RewriteEngine RewriteLog RewriteLogLevel RewriteMap RewriteRule

    [mod_rewrite模块常见用途]

    改变查询参数的设定位置

    [mod_rewrite模块标记]

    RewriteLog, 设置重写引擎日志的文件名

    RewriteRule, 设置重写规则

    [mod_rewrite模块常见问题]

    RewriteRule中的正则表达式需要考虑是否要加上^(匹配字符串开头)

    RewriteRule中的正则表达式需要考虑是否要对.转义(匹配任意字符还是仅匹配.字符)

    [apache其他常见问题]

    RedirectMatch用于简单的重定向

    最新回复(0)