【问题标题】:.htaccess conditions - OR statement.htaccess 条件 - OR 语句
【发布时间】:2011-01-04 18:56:21
【问题描述】:

我有一个代码:

RewriteCond %{REQUEST_FILENAME} ^(.*\.php)$    
RewriteCond %{REQUEST_FILENAME} ^(.*\.html)$    

但是它不起作用,因为我认为它会检查文件扩展名是否为 .php 和 .htm 这是不可能的...如何更改它以使其适用于 .php 或 .html?

【问题讨论】:

    标签: php html .htaccess


    【解决方案1】:

    以下将确保条件以逻辑 OR 连接:

    RewriteCond %{REQUEST_FILENAME} ^(.*\.php)$  [OR]  
    RewriteCond %{REQUEST_FILENAME} ^(.*\.html)$
    

    我会推荐以下稍微优化的内容 - 它严格确保扩展名(结束)和字段名捕获可以使用您的 RewriteRule 完成。

    RewriteCond %{REQUEST_FILENAME} \.php$  [OR]  
    RewriteCond %{REQUEST_FILENAME} \.html$
    

    【讨论】:

      【解决方案2】:
      RewriteCond %{REQUEST_FILENAME} ^(.*\.php|html)$
      

      【讨论】:

      • 正则表达式应为^(.*\.(php|html))$,否则将针对^(.*\.php)$^(html)$ 测试整个文件名。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 2021-07-04
      相关资源
      最近更新 更多