【问题标题】:.htaccess to allow .html.htaccess 以允许 .html
【发布时间】:2012-08-10 01:41:15
【问题描述】:

所以我让它将 .html 重写为 .php,但是当我需要它时它不会加载 .html 文件。有没有办法让它忽略书店目录?我以为我已经在里面了,但它不起作用。

/public_html/.htaccess
Options +FollowSymlinks
DirectoryIndex index.php index.html index.htm
RewriteEngine on
RewriteCond %{REQUEST_URI} "/bookstore/"
RewriteRule ^(.+)\.html$ http://virtualbookworm.com/$1.php [L]
ErrorDocument 404 /error.php

../bookstore/.htaccess
Options +FollowSymlinks
DirectoryIndex index.php index.html index.htm
Options +Indexes
ErrorDocument 404 /error.php

【问题讨论】:

    标签: php html .htaccess directory


    【解决方案1】:

    要忽略书店目录,需要在表达式前面加上!

    RewriteCond %{REQUEST_URI} !/bookstore/
    

    或者,您可以在bookstore 目录下的htaccess 文件中打开重写引擎,您的文档根目录中的规则将被取代:

    ../bookstore/.htaccess
    Options +FollowSymlinks
    DirectoryIndex index.php index.html index.htm
    Options +Indexes
    ErrorDocument 404 /error.php
    RewriteEngine On
    

    此外,在规则的目标中包含http://virtualbookworm.com 会导致浏览器被重定向(使用 302 响应),并且会更改地址栏中的 URL。如果这不是您想要的,只需将其删除:

    RewriteRule ^(.+)\.html$ /$1.php [L]
    

    【讨论】:

      【解决方案2】:

      试试

      RewriteCond %{REQUEST_URI} "/bookstore/"
      RewriteCond %{REQUEST_FILENAME} !-f 
      RewriteRule ^(.+)\.html$ http://virtualbookworm.com/$1.php [L]
      

      RewriteCond %{REQUEST_FILENAME} !-f 应该过滤掉请求,以便仅在“请求的”文件不存在时应用规则。

      【讨论】:

      • 值得注意的是,!-f 告诉 mod_rewrite 忽略任何实际存在的文件并将它们排除在重写之外。
      • @MarcB: 刚刚添加了这个 :) 感谢您指出 :)
      猜你喜欢
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 2019-03-25
      • 2014-10-23
      • 2015-06-17
      • 2018-04-19
      相关资源
      最近更新 更多