出于美学原因(我更喜欢URL和页面之间存在严格的一对一映射),我不喜欢http://www.example.com/index.html和http:// www。 example.com/通过两个不同的URL产生相同的内容。 我想有http://www.example.com/作为规范的。
明显的解决scheme:
Redirect permanent /index.html /
是错误的(无尽循环)。
更好的解决scheme? 这似乎令人惊讶的困难。
从mod_rewrite尝试一个RewriteCond
:
RewriteEngine On RewriteCond %{QUERY_STRING} !^/$ RewriteRule /index.html / [R]
这说如果查询string不是 /
然后重写/index.html
作为/
(不应该循环)。
从PP的回应中,我的解决scheme(似乎工作,所以我接受了)是:
重写引擎 RewriteCond%{REQUEST_URI} ^ \ / index \ .html $ RewriteRule。* http://www.example.com/ [R = 302,L]
任何非modrewrite解决scheme? 我不得不激活一个新的Apache模块,我试图避免。
RedirectMatch ^/index.html$ http://www.example.com/
为什么不把DirectoryIndex设置为别的东西 – 例如unpredictable.html,并且同样命名你的索引文件?
DirectoryIndex unpredictable.html Redirect permanent /index.html http://yoursite/
您不需要公开所选的DirectoryIndex值。
请注意,redirect的最后一个参数需要是完整的URL,而不仅仅是一个path片段。
一个非mod_rewrite的解决scheme…其实joschi几乎有它,但对于一些(我不清楚)的原因,你必须在无尽的循环kludge:
RedirectMatch permanent ^/index\.html$ http://www.example.com/ AliasMatch ^/$ /var/www/index.html
RewriteEngine on RewriteCond %{REQUEST_URI} ^\/index\.html$ RewriteRule .* http://www.example.com/ [R=302,L]
完美解决scheme