把所有的东西都重定向到index上(用htaccess,不搞乱图片)

问题描述 投票:0回答:1

我怎样才能把所有的东西都重定向到索引页(比如www.domain.comanything),而不影响本页的css、img和js加载?

这样做应该可以吗?

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/index.html
RewriteCond $1 !^(img|css|js|font)
RewriteRule ^(.*)$ /index.html [L,R=301]
.htaccess
1个回答
2
投票

我倾向于使用。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [QSA,L]

凡是 重写本子 -f 将匹配任何常规的文件调用(这些调用用 !). 所以你可以正常调用这些,其他的(包括404)都会被发送到索引中。

© www.soinside.com 2019 - 2024. All rights reserved.