如何从静态页面的URL中删除.html
?
此外,我需要将任何带有.html
的url重定向到没有它的url。(即从www.example.com/page.html
到www.example.com/page
)。
发布于 2011-04-20 20:19:21
在apache下的.htaccess中,你可以这样做重定向:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
至于从url中删除.html,只需链接到没有.html的页面
<a href="http://www.example.com/page">page</a>
发布于 2012-08-05 08:38:40
这对你来说应该是可行的:
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
发布于 2014-06-29 20:05:39
您需要确保您也安装了Options -MultiViews
。
以上这些都不适合我在标准cPanel主机上使用。
这是可行的:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
https://stackoverflow.com/questions/5730092
复制相似问题