于是,我找到了答案,以消除我的网页,与此代码工作正常,在.html扩展名:NGINX删除删除扩展名为.html
server {
listen 80;
server_name _;
root /var/www/html/;
index index.html;
if (!-f "${request_filename}index.html") {
rewrite ^/(.*)/$ /$1 permanent;
}
if ($request_uri ~* "/index.html") {
rewrite (?i)^(.*)index\.html$ $1 permanent;
}
if ($request_uri ~* ".html") {
rewrite (?i)^(.*)/(.*)\.html $1/$2 permanent;
}
location/{
try_files $uri.html $uri $uri/ /index.html;
}
}
但是,如果我打开mypage.com它重定向我mypage.com/index
这不是通过将index.html声明为索引来解决的吗?任何帮助表示赞赏。
页面的伟大工程你怎么使用302重定向,而不是301? – WillB
@WillB由于301重定向是由浏览器缓存的,我喜欢使用302,除非我100%确定我永远不想撤消重定向。从我看到的情况来看,Google似乎并不太在意,如果有一天您决定要回到URL中的.html扩展名中,它会变得更容易。 – Arnon
try_files语句应该在if块之外... – goliatone