启用了MultiViews的Apache Clean-Urls

Aad*_*rma 7 php apache .htaccess mod-rewrite apache2

我正在尝试允许启用MultiViews的Clean-Urls.

我拥有的所有页面都在根文件夹中.

我想要实现以下目标:

(current-status -> what I am trying to achieve)

 1. foo.com/services.php -> foo.com/services
 2. foo.com/services == foo.com/services/
 3. foo.com/services.php/second-level/ == foo.com/services/second-level
Run Code Online (Sandbox Code Playgroud)

services不是 一个文件夹,我爆炸$_SERVER['PATH_INFO']并获得第二级的路径数据.

我已经实现了第一个,但是当我启用MultiViews,使用.htaccess文件并写入重写时它失败了.

Options +Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Run Code Online (Sandbox Code Playgroud)

(这显然会失败,因为它会将请求更改为services/second-level.php).我知道我可以写入多个重写.htaccess,并有条件地重定向.

但奇怪的是,在实时环境(共享主机)上,它正在工作,根文件夹中没有任何.htaccess文件.由于它是共享主机,我无法读取配置文件.

有关我应该更改(in apache.conf*.conf)以实现上述内容的配置的任何想法?

如果重要,我正在使用Apache/2.2.22,这个问题在更新后开始发生.

Aad*_*rma 11

我终于弄明白了如何解决它.

这样可以.htaccess完全删除文件,并更改Virtual Directory以保留以下设置:

<VirtualHost *:80>
    ServerAdmin my-email-id
    ServerName foo.bar
    DocumentRoot /var/www/sites/foo/

    <Directory /var/www/sites/foo/>
        Options +FollowSymLinks +MultiViews +Indexes
        DirectoryIndex index.php
        AddType application/x-httpd-php .php
    </Directory>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

这有助于让所有页面正常工作,就像它们在服务器上工作一样,没有任何重写条件.