我已经改变了我的虚拟主机提供商,现在我有一个configuration问题:在我的网站的根,我有一个名为beta.html的文件。 即使以http://example.com/beta或http://example.com/beta/访问,以前的虚拟主机上的Apacheconfiguration也会提供其内容。 新的虚拟主机上的Apache将这两种情况视为404错误。 请注意,该网站上没有名为beta目录。
有没有什么我可以用.htaccess做到这一点,以便它服务beta.html的内容,而无需客户端redirect?
为有问题的Directory启用MultiViews 。
<Directory /my/web/site> Options MultiViews # and your other options </Directory>
我的第一个猜测是,您的旧托pipe服务提供商启用了Aapche的mod_speling ,这允许Apache在显示404错误之前更正小的案例不匹配和/或拼写错误。
最好的做法是放弃它,因为它可能会导致相当多的开销,并且不鼓励糟糕的网页devise。
你可以使用mod_rewrite来做到这一点。 网上有很多教程。
不过,我会提醒的是,由于冲突,复杂性和search引擎优化的原因,这不是一个推荐的做法。
例如,请参阅: 用htaccess重写.html文件扩展名我没有testing过,但看到有人使用这种方法。
请注意,这将影响您的整个网站。 如果你只想做一个URL,那么添加一个RewriteCond这样的过滤只适用于该URI。
# This tag ensures the rewrite module is loaded <IfModule mod_rewrite.c> # enable the rewrite engine RewriteEngine On # Set your root directory RewriteBase / # remove the .html extension RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP RewriteRule (.*)\.html$ $1 [R=301] # remove index and reference the directory RewriteRule (.*)/index$ $1/ [R=301] # remove trailing slash if not a directory RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} /$ RewriteRule (.*)/ $1 [R=301] # forward request to html file, **but don't redirect (bot friendly)** RewriteCond %{REQUEST_FILENAME}.html -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.html [L] </IfModule>