doucaishou0074 2013-08-09 19:55
浏览 39
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • doukaojie8573 2013-08-09 20:06
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?