启用多视图的 Apache Clean-Urls [英] Apache Clean-Urls with MultiViews enabled

查看:20
本文介绍了启用多视图的 Apache Clean-Urls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启用 Clean-Urls,并启用 MultiViews.

I'm trying to allow Clean-Urls, having MultiViews enabled.

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

All the pages I have, are in the root folder itself.

我正在努力实现以下目标:

I am trying to achieve the following :

(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

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

The services is not a folder, I explode $_SERVER['PATH_INFO'] and get the second-level path data.

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

I have already achieved the first one, but it fails when I enable MultiViews, using a .htaccess file and writing a rewrite.

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

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

(Which would obviously fail, since it would change the request to services/second-level.php). I know I can write multiple rewrites in the .htaccess, and conditionally redirect.

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

But the strange fact is that on the live environment (shared hosting), it is working, without any .htaccess file in the root folder. Since it is a shared hosting, I cannot read the configuration file.

关于我应该更改什么配置(在 apache.conf*.conf 中)以实现上述目标的任何想法?

Any ideas on what configuration should I change (in apache.conf or *.conf) to achieve the above?

如果有关系,我正在使用 Apache/2.2.22,并且此问题在更新后开始发生.

If it matters, I'm using Apache/2.2.22, and this problem started happening after the update.

推荐答案

我终于想出了如何解决它.

I finally figured out how to solve it.

这是有效的,完全删除 .htaccess 文件,并更改 Virtual Directory 以保留以下设置:

This works, removing the .htaccess file altogether, and changing the Virtual Directory to keep the following settings :

<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>

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

This helps me get all the pages to work, exactly as they were working on the server, without any of the Rewrite Conditions.

这篇关于启用多视图的 Apache Clean-Urls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆