为什么我不能使用下面的代码?
RewriteRule ^(.*)$ $1.html [L].htaccess文件:
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]发布于 2020-03-23 02:41:28
RewriteRule ^(.*)$ index.php L RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*)$ $1.html L
第一条规则将所有内容重写为index.php。后面的指令实际上被忽略了。
然而,第二条规则也会重写所有不会映射到现有文件或目录以附加.html扩展名的内容(相同的模式^(.*)$ -明显的冲突)。第二条规则更具限制性。
看起来你想做的是:
.html扩展附加到将映射到.html的URL,所有其他请求(我假设)不会映射到URL的物理文件和目录其他假设
root.
.htaccess文件的URL在URL-index.php (就像您所做的那样),那么它也会重写您的所有静态资源(CSS、JS、图像等),所以我假设您希望对静态资源和任何映射到文件或目录的内容进行例外处理。请尝试执行以下操作:
RewriteEngine On
# Append the ".html" extension if the target file exists
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.])$ $1.html [L]
# Rewrite other requests that don't map to files/directories to index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !\.(?:css|js|jpg|png|gif)$ index.php [L]https://stackoverflow.com/questions/60799627
复制相似问题