如何在PHP中使用斜线创建忽略路径


How can I make ignore path with slash in PHP?

有没有办法在一个文件中获得类似http://example.com/ad/dahttp://example.com/xx/zz的url(例如位于根目录中的index.php)?

我想得到这些路径ad/daxx/zz,并放入根文件夹(index.php)中的以下代码中

echo file_get_contents('http://www.example2.com/?'.$upper_path);

换句话说,我希望当用户转到http://example.com/ad/da URL时,我获取ad/da并放入以下代码

echo file_get_contents('http://www.example2.com/?'.$upper_path);

将以下规则添加到网站根目录/ 中的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index'.php [NC]
RewriteRule ^ index.php [L]

现在,所有传入的请求都将被路由到index.php,在那里您可以检索作为的路径

<?php
    echo file_get_contents('http://www.example2.com/?'.$_SERVER['REQUEST_URI']);
?>

如果您只希望某些URI发生这种情况,请使用此选项。

RewriteEngine on
RewriteCond %{REQUEST_URI} ^(/ad/da)|(/xx/zz) [NC]
RewriteRule ^ index.php [L]