.conf中具有mod_rewrite的SCRIPT_NAME和PHP_SELF [英] SCRIPT_NAME and PHP_SELF with mod_rewrite in .conf

查看:105
本文介绍了.conf中具有mod_rewrite的SCRIPT_NAME和PHP_SELF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将此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屋!

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