如何使用htaccess文件将所有页面(仅页面)重定向到index.html,而不重定向图像文件。由于某种原因,我正在使用这段代码,index.html页面上的一个图像文件没有显示出来。
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .* /index.html [L,R=302]
发布于 2013-07-18 04:26:40
尝试以下代码:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]
发布于 2013-07-18 04:35:02
让你的规则保持简单。只需要匹配文件,而不是过滤不应该匹配的内容。
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .*\.(php|html)$ /index.html [L,R=302]
发布于 2018-09-10 10:56:53
一种更好的方式可能是忽略现有文件。例如:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* / [L,R=302]
!-d
表示,如果存在满足匹配条件的现有目录,则忽略重写。
!-f
表示,如果存在满足匹配条件的现有文件,则忽略重写。
其他的一切都会被重写。
https://stackoverflow.com/questions/17709500
复制相似问题