.htaccess允许.html
问题描述:
所以我把它重写为.html给.php,但是当它需要时它不会加载.html文件。有没有办法让它忽略书店目录?我以为我已经在那里,但它不起作用。.htaccess允许.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
答
要忽略书店的目录,你在表达的前面需要一个!
:
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]
答
尝试
RewriteCond %{REQUEST_URI} "/bookstore/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ http://virtualbookworm.com/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
应请求进行过滤出来,所以仅应用于规则如果“要求”文件不存在。
注意,'!-f'告诉mod_rewrite忽略任何实际存在的文件并将它们从重写中排除。 – 2012-08-13 19:25:28
@MarcB:刚刚添加这个:)谢谢指出:) – 2012-08-13 19:28:27