Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用.htaccess重写路径变量_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php 使用.htaccess重写路径变量

Php 使用.htaccess重写路径变量,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在创建需要与一些PC软件进行通信的。当PC软件调用脚本int时,需要包括用户名和PHP需要读取的服务器上文件的相对路径 这是get.PHP中的PHP: $Username = $_GET['Username']; $RelativePath = $_GET['Path']; 未重写的URL如下所示: 现在我想将其改写为: 但我有问题,因为路径包含斜杠 如何使用路径中的多个文件夹重写它?您可以在站点根目录中使用此规则。htaccess: Options -MultiViews Rewri

我正在创建需要与一些PC软件进行通信的。当PC软件调用脚本int时,需要包括用户名和PHP需要读取的服务器上文件的相对路径

这是get.PHP中的PHP

$Username = $_GET['Username'];
$RelativePath = $_GET['Path'];
未重写的URL如下所示:

现在我想将其改写为:

但我有问题,因为路径包含斜杠


如何使用路径中的多个文件夹重写它?

您可以在站点根目录中使用此规则。htaccess:

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^get/([^/]+)/(.+)$ get.php?Username=$1&Path=$2 [L,QSA,NC]

+
将匹配任何字符中的一个或多个,包括
/

您可以在站点根目录中使用此规则。htaccess:

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^get/([^/]+)/(.+)$ get.php?Username=$1&Path=$2 [L,QSA,NC]
+
将匹配任何字符中的一个或多个,包括
/