强制网页存在于' /'?

时间:2015-07-30 20:54:12

标签: apache .htaccess url mod-rewrite url-rewriting

是否可以使用以下网址:

http://example.com//

我知道'正向斜线'最后是无效的(因为页面不能命名:' /'或者它可以吗?) - 但是有一种方法,通过使用.htaccess强制网页存在于该位置(除了索引页面。)

因此,http://example.com/是索引页面,但当用户输入:http://example.com//时,他们会获得另一个网页。

你知道,我的问题是我需要一个角色'页面 - 并保持一致性' /'是最好的。

(我知道不建议这样做:可能会引发负面反应 - 但是,为了兴趣,我看到这是否可行 - 一个.htaccess解决方案会很棒。)

1 个答案:

答案 0 :(得分:0)

这是一种可以执行此操作的方法:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s//[\s?]
RewriteRule ^ another-page.php [L]

这会为/index.php显示http://example.com/,并为/another-page.php显示http://example.com//