规则将我的路径转换为整个查询

规则将我的路径转换为整个查询

问题描述:

Example :

I go in the browser at :

www.example.com/documents/pages/doc.php?bacon=baked&this=tastes_good

And I would like that this link access to this page with the path encoded into the query :

www.example.com/index.php?url=documents%2Fpages%2Fdoc.php%3Fbacon%3Dbaked%26this%3Dtastes_good

The thing is that this index.php will need to take the big "url" query variable to decode and modify it in PHP and then fopen() the wanted page from an other site.
I need to do all that because the two sites need to use the same $_SESSION, databases and files and it would be harder to completely separate.

示例: h3>

我进入浏览器: p>

www.example.com/ documents / pages / doc.php?bacon = baked& this = tastes_good strong> p> blockquote>

我希望此链接能够使用编码到查询中的路径访问此页面: p>

www.example.com/index。 php?url = 文件%2Fpages%2Fdoc.php%3Fbacon%3Dbaked%26this%3Dtastes_good strong> p> blockquote>

事情就是这个索引。 php将需要使用大的“url”查询变量来解码并在PHP中修改它,然后从其他站点fopen()想要的页面。
我需要做所有这些,因为这两个站点需要使用 相同的$ _SESSION,数据库和文件,完全分离将更难。 p> div>

Assuming you have your .htaccess in your web root / directory

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/index\.php [NC]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ index.php?url=$1%3F%1 [B,NE,L]

You may have to enable AllowEncodedSlashes in your server's httpd.conf configuration file if you still find those /s not getting encoded to %2F.