mod_rewrite和PATH_INFO与PHP项目

我有一个项目读取$_SERVER['PATH_INFO']variables时加载页面,因此它读取格式为http://address/index.php/pagename的页面 ,我想使用mod_rewrite删除索引。 PHP的一部分的url,并使以前的URL http://地址/ pagename 。 如果访问http:// address / pagename ,则需要像访问http://address/index.php/pagename一样加载页面。

使用Nginx,下面的configuration工作,并重写…

 server { listen 80; server_name localhost; root /srv/http/web/html; index index.php; location ~ ^/[^/]+\.php($|/) { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_split_path_info ^(/[^/]+\.php)(/.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } location ~ .* { rewrite ^/(.*)$ /index.php/$1 last; } } 

我将如何完成这个在Apache中。 我目前正在工作,以便根显示正确,并与index.php部分工作编写url。 我怎样才能使重写规则工作,仍然能够使用$_SERVER['PATH_INFO']variables? 我可以在.htaccess中添加什么function?

当php像模块一样编译时,不能直接从apache内部更改$_SERVER["PATH_INFO"]variables。

但是这里有一个解决方法可以完成这项工作:

  1. 使用以下内容创build一个rewrite_pathinfo.php文件:

    <?php if(!empty($_SERVER['PATH_INFO'])) header("Location: ".$_SERVER['PATH_INFO']); $_SERVER['PATH_INFO'] = $_SERVER['REDIRECT_ORIGINAL_PATH']; ?>

  2. 把它放到你的.htaccess

    php_value auto_prepend_file "/var/www/vhosts/path_to_your/rewrite_pathinfo.php"

    RewriteEngine On

    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule (.*) /index.php [QSA,L,PT,E=ORIGINAL_PATH:/$1]