如何在htaccess中替换-MultiViews行为?

时间:2015-01-31 12:21:15

标签: php apache .htaccess

我正在尝试捕获对目录及其子目录中的文件的所有请求,并将它们路由到子目录中的单个文件。这是htaccess指令的样子:

Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine On

  # Excluding one directory
    RewriteRule ^(excludedfolder)($|/).*\.(php)$ - [L]

  # Redirect everything that is html or php to magicscript
    RewriteRule \.(php|html|phps)$ /excludedfolder/magicscript.php [L]
    RewriteRule ^/?$ /excludedfolder/magicscript.php [L]
    RewriteRule ^/?index.php$ /excludedfolder/magicscript.php [L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . excludedfolder/magicscript.php [L]
</IfModule>

这适用于大部分系统。

如果我致电someserver.com/testfile.php,则会将其正确路由至magicfile.php。如果我拨打someserver.com/testfile,它也会正确路由到magicfile.php。子文件夹也是如此:如果我拨打someserver.com/somefolder/testfile.phpsomeserver.com/somefolder/testfile,则会将其正确路由到magicfile.php

但在某些服务器上,不允许设置导致服务器完全失败的Options -MultiViews。如果我删除该选项,它仍然有效,但如果我不添加文件扩展名则不会。

如何在不使用magicfiles.php的情况下将非现有文件重定向到Options -MultiViews?或者如何检测是否允许在php中设置选项?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

也许服务器不支持Options -MultiViews http://httpd.apache.org/docs/2.2/mod/core.html#options

相关问题