2014-03-27 12 views
2

我的问题是,如何以每种URL末尾添加.html的方式来重写我所有的URL?重写规则,以根目录和其他目录中包含/index.html的.html结束所有URL

,这里是我的.htaccess规则,我有

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ index.php/$1 

</IfModule> 

我曾尝试加入的.html到index.php/$1.html但这是投掷404所有的地方。

请帮

回答

2

您可以使用:

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^.]+?)/?$ $1.html [R=301,L,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^.]+)\.html$ index.php/$1 [L,NC] 

</IfModule> 
+0

谢谢,它的工作在一定程度上,但它没有这样做是没加的.html当我进入“codemysite.com/索引“,我期待的是在url的末尾添加.html,就像'mysite.com/index.html'一样。 – AlexB

+0

非常感谢,完美的作品 – AlexB

+0

其实还有一个非常小的问题,如果你的目录中的索引没有像mysite.com/index.html那样暴露出来,而是你有mysite.com/而不是mysite.com/.html,想法为什么? – AlexB