【问题标题】:adding one exception to url rewriting为 url 重写添加一个例外
【发布时间】:2014-09-11 13:23:55
【问题描述】:

我有以下 .htaccess 文件内容:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php\?p=((?![^&]*?edit)[^\s&]+) [NC]

RewriteCond %{THE_REQUEST} /index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]

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

这会重写如下 URL: http://domain.com/index.php?p=Contacts&ms=m5&l=en&

进入这个: http://domain.com/Contacts

它还排除了在变量 p 末尾包含单词“edit”的 URL,例如: http://domain.com/index.php?p=Contactsedit&l=en

我想在我的 .htaccess 文件中再添加一个排除条件,也就是排除变量 p 中包含单词“admin”的 url,例如: http://domain.com/index.php?p=admin

你们能帮我修改条件或添加排除条件吗?

非常感谢

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    像这样修改你的第一个条件:

    RewriteCond %{THE_REQUEST} /index\.php\?p=(?!admin)((?![^&]*?edit)[^\s&]+) [NC]
    

    (?!admin) 是一个否定的前瞻,它断言后面的不是admin

    参考

    【讨论】:

      猜你喜欢
      • 2020-04-02
      • 2015-04-14
      • 1970-01-01
      • 2010-11-30
      • 2016-12-19
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多