【问题标题】:How do I ignore a RedirectMatch .htaccess rule from a parent directory?如何忽略父目录中的 RedirectMatch .htaccess 规则?
【发布时间】:2023-03-24 05:59:02
【问题描述】:

我最近修改了我的网站,以便将 PHP 用于常见元素。然后我上传了这个 .htaccess 文件:

RedirectMatch permanent ^(.*)\.htm(l?)$ $1.php 

将对 .htm 或 .html 页面的请求重定向到相应的 .php 页面。但是,我的主机的统计信息管理器(位于我的 /public/ 目录中的 /stats/ 目录中)使用 .html 页面,这些页面现在被重定向到不存在的 .php 页面,因此返回 404 错误。如何设置 .htaccess 以便不将重定向应用到 /stats/ 目录中的页面?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    尝试将重定向匹配 (mod_alias) 改为使用 mod_rewrite,然后添加一个条件以排除所有 /stats/ 请求:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/stats/
    RewriteRule ^(.*)\.html?$ /$1.php [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2019-03-13
      • 2012-07-15
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 2015-07-20
      相关资源
      最近更新 更多