Mod rewrite mod_重写重复内容

Mod rewrite mod_重写重复内容,mod-rewrite,Mod Rewrite,我喜欢去掉重复的内容。 我的网站可以访问www,也可以不访问www。所以我做了如下修改: rewritecond %{http_host} ^example.com [nc] rewriterule ^(.*)$ http://www.example.com [r=301,nc] 我的问题是,我仍然可以到达该网站与/索引和不在最后。以及有无.html 我喜欢在URL中显示索引。example.com www.example.com全部重定向到www.example.com/index 带htm

我喜欢去掉重复的内容。 我的网站可以访问www,也可以不访问www。所以我做了如下修改:

rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com [r=301,nc]
我的问题是,我仍然可以到达该网站与/索引和不在最后。以及有无.html

我喜欢在URL中显示索引。example.com www.example.com全部重定向到www.example.com/index


带html和不带html适用于我的所有子页面。有没有办法总是删除html

我不确定我是否理解您的意图,但也许就是这样:

RewriteCond ${HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=permanent]
RewriteRule ^/?$ /index [L,R=permanent]
RewriteRule ^index$ index.html [L]
这将强制“www.”出现在域的开头,重定向对裸域的请求或“/”重定向到/index,然后默默地重写对/index的请求,以便它们实际获取/index.html的内容