Regex 配置htaccess以获取而不是目录
我有这样的url: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 ^([^/]+)/([^/
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¶m2=$2¶m3=$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¶m2=$2¶m3=$3 [QSA,L]