简体   繁体   中英

How to replace -MultiViews behaviour in htaccess?

I am trying to catch ALL requests to files in a directory and it's subdirectories and to route them to one single file in a subdirectory. Here is what the htaccess directives look like:

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>

This works on the mostpart of systems.

If i call someserver.com/testfile.php , it is properly routed to magicfile.php . If i call someserver.com/testfile , it also is properly routed to magicfile.php . The same for subfolders: If i call someserver.com/somefolder/testfile.php or someserver.com/somefolder/testfile , it is properly routed to magicfile.php .

But on some servers, it is not allowed to set the Options -MultiViews which causes the server to completely fail. If I remove the option, it still works, but it doesn't if I don't add the file extension.

How to redirect non existing files to magicfiles.php without having to use Options -MultiViews ? Or how to detect if it is allowed to set the option in php?

Thanks for your help!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM