【问题标题】:need mod_rewrite exceptions for urls starting with certain characters以某些字符开头的 url 需要 mod_rewrite 例外
【发布时间】:2014-03-18 23:10:56
【问题描述】:

我对 mod_rewrite 了解不多,但似乎找不到这个问题的答案。我正在开发一个简单的应用程序并通过 index.php 主页面路由所有 url(少数除外)。因此,例如 mysite.com/test 转到 index.php,然后在 php 中确定 url 是什么并加载适当的页面。

我的问题是我需要从该规则中排除电子邮件验证或其他潜在的未来例外情况。电子邮件验证链接的示例是:http://myrul.com/php-login-advanced/register.php?id=2&verification_code=..... 等。

所以...有没有办法从以某些字符开头的重写规则中排除 url。 "php-" 在这种情况下可以解决问题。

我目前的重写条件是:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|&|register\.php|php|
css|images|javascript|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    您可以使用 RewriteCond %{REQUEST_URI} 排除特定的 URI,如下所示:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/php- [NC]
    RewriteCond $1 !^(index\.php|register\.php|php|css|images|javascript|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    【讨论】:

      【解决方案2】:

      尝试使用查询字符串

      RewriteCond %{QUERY_STRING}     ^query=(.*)$    [NC]
      

      【讨论】:

      • 此字符串使激活链接起作用,但是会中断发送 mysite.com/login 或通过 index.php 主页面发送的任何其他内容。在玩了一会儿之后,如果有办法只允许 php 变量,我可以修改我现有的代码。
      猜你喜欢
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      相关资源
      最近更新 更多