.conf中具有mod_rewrite的SCRIPT_NAME和PHP_SELF [英] SCRIPT_NAME and PHP_SELF with mod_rewrite in .conf
问题描述
将此mod_rewrite从.htaccess
移到apache2.conf
后,$_SERVER['SCRIPT_NAME']
和$_SERVER['PHP_SELF']
都返回与其他值不同的值.
After moving this mod_rewrite from .htaccess
to apache2.conf
both $_SERVER['SCRIPT_NAME']
and $_SERVER['PHP_SELF']
returns different values than else..
# point all requests to index.php
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L,NS]
示例
URL:
example
URL:
http://domain.com/path/to/dir/
如果重写在.htaccess
中,则$_SERVER['PHP_SELF']
返回/index.php
If the rewrite is in .htaccess
then $_SERVER['PHP_SELF']
returns /index.php
如果重写在apache2.conf
中,则$_SERVER['PHP_SELF']
返回/path/to/dir/
If the rewrite is in apache2.conf
then $_SERVER['PHP_SELF']
returns /path/to/dir/
$_SERVER['PHP_SELF']
不起作用时,如何获取到文档根目录的相对路径?
How to get the relative path to doc root when $_SERVER['PHP_SELF']
doesn't work?
推荐答案
您应该尝试使用这样的规则,实际上它与config或.htaccess中的位置无关紧要.但是,如果使用apache配置,请确保它在Directory
指令中.并重新启动apache进行任何配置更改.
You should try using your rule like this and it really shouldn't matter where it's located as in the config or .htaccess. However make sure it's in a Directory
directive if using the apache config. And restart apache for any config changes.
<Directory /var/path/to/root>
RewriteEngine On
RewriteBase /
# point all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
这篇关于.conf中具有mod_rewrite的SCRIPT_NAME和PHP_SELF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!