删除扩展和静态的html加斜杠 [英] Remove extension and add slash on static html

查看:138
本文介绍了删除扩展和静态的html加斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的根目录中包含一些.html文件。 我想删除的.html在地址栏中的扩展,在这样的结尾添加斜线:的http://域名。 COM /页/ 我试过很多的解决方案,其中之一:

My root dir contains some .html files. I want to remove an extension of .html in address bar and add a slash in the end like this: http://domain.com/page/ I've tried lots of solutions, one of them:

RewriteEngine on
RewriteBase /

# redirect from ww to non-www
RewriteCond %{HTTP_HOST} ^www.nightmaar.com$ [NC] 
RewriteRule ^(.*)$ http://nightmaar.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.html
RewriteRule (.*)\.html$ /$1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.html [L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule .*[^/]$ $0/ [L,R=301]

但浏览器提供了一个错误(过多的重定向)。当我试图访问我的静态HTML页面,也没有重定向从page.html即可到/页/可言。

But the browser gives an error (too many redirects). When i'm trying to access my static html pages, there no redirects from page.html to /page/ at all.

请帮我解决这个问题:•

Help me please to solve this problem :S

推荐答案

您几乎做到了!

下面是应该工作:

RewriteEngine On
RewriteBase /

# redirect from www to non-www
RewriteCond %{HTTP_HOST} ^www.nightmaar.com$ [NC] 
RewriteRule ^(.*)$ http://nightmaar.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.html
RewriteRule (.*)\.html$ /$1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.html [L]

# Remove trailing slash:
RewriteRule (.*)/$ $1 [L]

# Now test without the trailing slash:
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule . %{REQUEST_FILENAME}.html [QSA,L]

这篇关于删除扩展和静态的html加斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆