问题:
我需要将edit/profil
重定向到edit.php?p=profil
,但p
参数不发送到edit.php
。你知道这可能是什么原因吗?
详细信息:
服务器是一个共享服务器,所以我无法访问Apache配置文件。我的文件夹位于/fr/intranet
中,包含两个文件:edit.php
和.htaccess
。edit.php
的内容很简单:
<?php
echo '<pre>';
echo "This is edit.php'n";
var_dump($_GET);
echo '</pre>';
?>
.htaccess
的内容如下:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /fr/intranet/
RewriteRule ^edit/profil/?$ edit.php?p=profil [L]
RewriteRule ^test/profil/?$ edit.php?p=profil [L]
当我加载/fr/intranet/test/profil
时,PHP脚本显示:
This is edit.php
array(1) {
["p"]=>
string(6) "profil"
}
当我加载/fr/intranet/edit/profil
时(这就是我在这里发布的原因(,PHP脚本显示:
This is edit.php
array(0) {
}
到目前为止我测试了什么
Parent.htaccess冲突
在/fr/文件夹中安装了一个带有.htaccess的Wordpress。我想知道它是否有一些重写规则与我的冲突。它不应该,因为我的htaccess有优先权。此外,没有任何规则可以产生我遇到的行为:
RewriteEngine On
RewriteBase /fr/
RewriteRule ^index'.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*'.php)$ $2 [L]
RewriteRule . index.php [L]
QSA标志
我知道QSA标志,但这不是问题所在。如果我理解正确,QSA标志在重定向时会查找整个URL(包括GET参数(,但我在请求的URL中没有GET参数。添加它不会改变行为。
正在创建test.php
如果我创建一个名为/fr/intranet/test.php
的文件,其中包含以下内容:
<?php
echo '<pre>';
echo "This is test.php'n"
var_dump($_GET);
echo '</pre>';
?>
如果我加载/fr/intranet/test/profil
,那么我得到以下输出:
This is test.php
array(0) {
}
此外,如果我删除了.htaccess
文件,则加载/fr/intranet/test
将显示/fr/intranet/test.php
的输出。
一切都表现得像有一个或多或少像这样的隐藏规则:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+).*$ $1.php [L]
RewriteEngine关闭/打开
我在这里发现,在.htaccess
文件中先关闭再打开"重写引擎"可能会禁用父重写规则。但这并没有解决我的问题。
尝试禁用多视图(Options -MultiViews
(,在这种情况下,它往往是罪魁祸首。
(有关"多视图"功能的详细说明,请参阅http://httpd.apache.org/docs/2.2/en/mod/mod_negotiation.html#multiviews.当存在与试图重写的"伪"路径段具有相同名称[减去扩展名]的文件时,这通常会干扰重写。(