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

如何在PHP中使用斜杠创建忽略路径?,php,regex,apache,.htaccess,apache2,Php,Regex,Apache,.htaccess,Apache2,有没有办法像http://example.com/ad/da或http://example.com/xx/zz在一个文件中(例如位于根目录中的index.php) 我想获得这些路径ad/da或xx/zz,并将其放入根文件夹(index.php)中的后续代码中 换句话说,当用户转到http://example.com/ad/daURL我获取ad/da并放入下面的代码中 echo file_get_contents('http://www.example2.com/?'.$upper_path);

有没有办法像
http://example.com/ad/da
http://example.com/xx/zz
在一个文件中(例如位于根目录中的index.php)

我想获得这些路径
ad/da
xx/zz
,并将其放入根文件夹(index.php)中的后续代码中

换句话说,当用户转到
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']);
?>

我不知道你在问什么,但我认为你正在努力调查。htaccess,但请随意澄清更多。你尝试了什么,正如前面所述,不清楚你想做什么。示例代码或使用示例数据的更具描述性的描述可能会获得更多帮助。@Naruto我更新了问题。谢谢你的关注。@talegna我更新了这个问题。谢谢你的关注。
<?php
    echo file_get_contents('http://www.example2.com/?'.$_SERVER['REQUEST_URI']);
?>
RewriteEngine on

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