Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 使用两个$GET变量重写URL_Php_.htaccess - Fatal编程技术网

Php 使用两个$GET变量重写URL

Php 使用两个$GET变量重写URL,php,.htaccess,Php,.htaccess,我目前正在处理我的.htaccess文件,以使我的URL看起来更干净。我用一个变量设法解决了这个问题,因此我成功地更改了: http://domain.com/index.php?role=Top 进入: 而我的.htaccess页面可以这样做: Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule

我目前正在处理我的.htaccess文件,以使我的URL看起来更干净。我用一个变量设法解决了这个问题,因此我成功地更改了:

http://domain.com/index.php?role=Top
进入:

而我的.htaccess页面可以这样做:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1
现在我想弄清楚的是如何:

http://domain.com/result.php?champ1=foo&champ2=bar
进入:


在我的.htaccess文件中有这样做的方法吗?

您只需将另一个捕获组添加到正则表达式中:

RewriteRule ^lane/(\w+)/(\w+)$ ./result.php?champ1=$1&champ2=$2
将导致能够做到:

http://domain.com/matchup/foo/bar
或者特别是你要求的:

RewriteRule ^lane/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2

大括号()内表达式的每个部分都定义为一个捕获组。因此,这是提取并作为$1、$2等推送到目标字符串中的部分。

您只需将另一个捕获组添加到正则表达式中:

RewriteRule ^lane/(\w+)/(\w+)$ ./result.php?champ1=$1&champ2=$2
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1

# new rewrite rule
RewriteRule ^ matchup/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
将导致能够做到:

http://domain.com/matchup/foo/bar
或者特别是你要求的:

RewriteRule ^lane/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2

大括号()内表达式的每个部分都定义为一个捕获组。因此,这是提取并作为$1、$2等推送到目标字符串中的部分。

您只需将另一个捕获组添加到正则表达式中:

RewriteRule ^lane/(\w+)/(\w+)$ ./result.php?champ1=$1&champ2=$2
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1

# new rewrite rule
RewriteRule ^ matchup/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
将导致能够做到:

http://domain.com/matchup/foo/bar
或者特别是你要求的:

RewriteRule ^lane/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2

大括号()内表达式的每个部分都定义为一个捕获组。因此,这是提取并作为$1、$2等推送到目标字符串中的部分。

您只需将另一个捕获组添加到正则表达式中:

RewriteRule ^lane/(\w+)/(\w+)$ ./result.php?champ1=$1&champ2=$2
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1

# new rewrite rule
RewriteRule ^ matchup/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
将导致能够做到:

http://domain.com/matchup/foo/bar
或者特别是你要求的:

RewriteRule ^lane/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
大括号()内表达式的每个部分都定义为一个捕获组。因此,这是提取并作为$1、$2等推入目标字符串的部分。

您可以使用:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^lane/(\w+)$ ./index.php?role=$1
RewriteRule ^lane/(\w+)/$ ./index.php?role=$1

# new rewrite rule
RewriteRule ^ matchup/(\w+)&(\w+)$ ./result.php?champ1=$1&champ2=$2
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^lane/(\w+)/?$ index.php?role=$1 [L,QSA,NC]

RewriteRule ^matchup/(\w+)&(\w+)/?$ result.php?champ1=$1&champ2=$2 [L,QSA,NC]
您可以使用:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^lane/(\w+)/?$ index.php?role=$1 [L,QSA,NC]

RewriteRule ^matchup/(\w+)&(\w+)/?$ result.php?champ1=$1&champ2=$2 [L,QSA,NC]
您可以使用:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^lane/(\w+)/?$ index.php?role=$1 [L,QSA,NC]

RewriteRule ^matchup/(\w+)&(\w+)/?$ result.php?champ1=$1&champ2=$2 [L,QSA,NC]
您可以使用:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^lane/(\w+)/?$ index.php?role=$1 [L,QSA,NC]

RewriteRule ^matchup/(\w+)&(\w+)/?$ result.php?champ1=$1&champ2=$2 [L,QSA,NC]

这正是我想要的方式!现在,唯一的问题是变量中有两个带空格的单词。例如,
http://domain.com/matchup/Kha%20Zix&Ahri/Middle
I get
在此服务器上找不到请求的URL/matchup/Kha-Zix&Ahri/Middle。
是否有办法使两个单词变量都能工作?如果您想匹配任意多个单词,可以使用这种正则表达式:
([\w\s]+)和([\s\w]+)
这正是我想要的方式!现在,唯一的问题是变量中有两个带空格的单词。例如,
http://domain.com/matchup/Kha%20Zix&Ahri/Middle
I get
在此服务器上找不到请求的URL/matchup/Kha-Zix&Ahri/Middle。
是否有办法使两个单词变量都能工作?如果您想匹配任意多个单词,可以使用这种正则表达式:
([\w\s]+)和([\s\w]+)
这正是我想要的方式!现在,唯一的问题是变量中有两个带空格的单词。例如,
http://domain.com/matchup/Kha%20Zix&Ahri/Middle
I get
在此服务器上找不到请求的URL/matchup/Kha-Zix&Ahri/Middle。
是否有办法使两个单词变量都能工作?如果您想匹配任意多个单词,可以使用这种正则表达式:
([\w\s]+)和([\s\w]+)
这正是我想要的方式!现在,唯一的问题是变量中有两个带空格的单词。例如,
http://domain.com/matchup/Kha%20Zix&Ahri/Middle
I get
在此服务器上找不到请求的URL/matchup/Kha Zix&Ahri/Middle。
是否有办法使两个单词变量都能工作?如果您想匹配任意多个单词,可以使用这种正则表达式:
([\w\s]+)和([\s\w]+)