Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Regex 配置htaccess以获取而不是目录_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex 配置htaccess以获取而不是目录

Regex 配置htaccess以获取而不是目录,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我有这样的url: www.mydomain.com/index.php?param1=first¶m2=second¶m3=thirth 我想把它改写成: www.mydomain.com/first/second/third .htaccess RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/

我有这样的url:

www.mydomain.com/index.php?param1=first¶m2=second¶m3=thirth

我想把它改写成:

www.mydomain.com/first/second/third

.htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/([^/]+)$ index.php?param1=$1&param2=$2&param3=$3 [QSA,L]

问题是,我得到了错误404(我认为服务器正在查找目录/first/second/third,而不是让root dir中的index.php从URL获取参数)。我错了吗?或者如何处理这个问题?

您的正则表达式实际上是不正确的。您在目标中使用了3个反向参考值,但只捕获了2个值

您可以使用:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?param1=$1&param2=$2&param3=$3 [QSA,L]