【问题标题】:Alternative for Options MultiViews on new Apache新 Apache 上的 Options MultiViews 的替代方案
【发布时间】:2014-12-17 20:17:38
【问题描述】:

我在 htaccess 中使用

AcceptpathInfo On
Options MultiViews
MultiviewsMatch Handlers

设置漂亮的 URL 等等。这将文件名中的扩展名设置为可选。例如http://server.com/index 将与http://server.com/index.php 相同(在 robots.txt.php、style.css.php 等中更有用)。但是在更新到新版本的 XAMPP(Apache 2.4.10 和 PHP 5.6.3)后它不起作用(错误 403),但在旧 XAMPP 中它可以工作。你知道这个或如何设置它的任何替代方案吗?错误在行

Options MultiViews

【问题讨论】:

  • 你确定这与多视图有关吗?
  • 是的,它被用在书中(CZ;1001 tip... a triků pro PHP;Jakub Vrána;2012),我在许多 Web 项目中都使用了它,并且每次都有效。
  • 因此,如果您删除 Multiviews 选项,您将不再获得 403?
  • 是的,当我删除 Options MultiViews 它返回 200 但没有文件扩展名的请求不起作用。

标签: php apache .htaccess xampp pretty-urls


【解决方案1】:

实际上,注意到了一些可以解决您的问题的方法。因此,对于 apache 2.4,您需要在每个选项前面加上 +-,因此您需要:

Options +Multiviews

如果这仍然不起作用,也许 mod_rewrite 可以做到(但您需要尝试每个扩展)。比如:

RewriteEngine On

# check for PHP extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ /$1.php [L]

# chek for HTML extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.*)$ /$1.html [L]

等等。对于您要检查的每个扩展程序。

【讨论】:

    猜你喜欢
    • 2015-03-16
    • 2011-03-26
    • 2014-12-27
    • 1970-01-01
    • 2015-07-31
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多