简体   繁体   中英

.htaccess to allow .html

so I have it rewriting .html to .php, but then it won't load .html files when I need it to. Is there a way to get it to ignore the bookstore directory? I thought I have that in there already, but it doesn't work.

/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

To ignore the bookstore directory, you need a ! in front of the expression:

RewriteCond %{REQUEST_URI} !/bookstore/

Or, you can just turn on the rewrite engine in the htaccess file in the bookstore directory and the rules in your document root will be superceded:

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

Additionally, the inclusion of the http://virtualbookworm.com in the rule's target will cause the browser to be redirected (using a 302 response) and it'll change the URL in the address bar. If that's not what you want, just remove it:

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

Try

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

RewriteCond %{REQUEST_FILENAME} !-f should filter requests out, so that the rule is only applied if the 'requested' file does not exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM