gpt4 book ai didi

php - 启用了 MultiViews 的 Apache Clean-Urls

转载 作者:可可西里 更新时间:2023-11-01 12:49:55 25 4
gpt4 key购买 nike

我正在尝试允许 Clean-Urls,启用 MultiViews。

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

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

(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']得到二级路径数据。

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

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

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

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

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

如果重要的话,我正在使用 Apache/2.2.22,这个问题在更新后开始出现。

最佳答案

我终于想出了解决办法。

这有效,完全删除 .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>

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

关于php - 启用了 MultiViews 的 Apache Clean-Urls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14182741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com