htaccess regex获取附加字段
我有下面的正则表达式,虽然它只选择了一个变量,并将其放在user-like-user-contains-user/url中,但我如何修改它以分别在$2中获取url变量htaccess regex获取附加字段,regex,.htaccess,Regex,.htaccess,我有下面的正则表达式,虽然它只选择了一个变量,并将其放在user-like-user-contains-user/url中,但我如何修改它以分别在$2中获取url变量 RewriteCond %{HTTP_HOST} ^(^.*)\.example.com$ [NC] RewriteRule ^(.+/?[^/]*)$ http://example.com/index.php?sub=%1&url=$1 [P,NC,QSA,L] 我需要这个来翻译 http://sub.example.
RewriteCond %{HTTP_HOST} ^(^.*)\.example.com$ [NC]
RewriteRule ^(.+/?[^/]*)$ http://example.com/index.php?sub=%1&url=$1 [P,NC,QSA,L]
我需要这个来翻译
http://sub.example.com/user/url
到
从
RewriteCond
和RewriteRule
中捕获2个值的正则表达式似乎不正确
您可以使用:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^([^/]+)(?:/([^/]+))?/?$ http://example.com/index.php?sub=%1&user=$1&url=$2 [P,NC,QSA,L]
我假设您使用了
p
标志,所以设置了mod_proxy
。谢谢,我需要可选的参数,所以我将其更新为RewriteRule^([^/]+)/?([^/]+)/?$[p,NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^([^/]+)(?:/([^/]+))?/?$ http://example.com/index.php?sub=%1&user=$1&url=$2 [P,NC,QSA,L]