我是 .htaccess 的新手,想从 .htaccess 重定向 URL
喜欢:
http://test.example.com/abc/xyz/456adf646asdf
至
http://test.example.com/abc/xyz?id=456adf646asdf
或 http://test.example.com/abc/xyz/?456adf646asdf
请帮忙。
我试过这个:
重写规则 ^(.+)/abc/xyz/$ /abc/xyz?id=$1
但对我不起作用..
我是 .htaccess 的新手,想从 .htaccess 重定向 URL
喜欢:
http://test.example.com/abc/xyz/456adf646asdf
至
http://test.example.com/abc/xyz?id=456adf646asdf
或 http://test.example.com/abc/xyz/?456adf646asdf
请帮忙。
我试过这个:
重写规则 ^(.+)/abc/xyz/$ /abc/xyz?id=$1
但对我不起作用..
您还应该有一个 RewriteCond 来匹配传入的 URL 模式。试试这个来匹配你的明确案例。
RewriteCond %{REQUEST_URI} ^/abc/xyz/(.\*)
RewriteRule (.\*) /abc/xyz?id=%1 [L]
当然有很多选择。你也可以试试
RewriteCond %{REQUEST_URI} ^/(.\*)/(.\*)/(.\*)
RewriteRule (.\*) /%1/%2?id=%3 [L]
在您的示例中,%1 将匹配“abc”,%2 将匹配“xyz”,而 %3 456adf646asdf。
是否安装了 mod_rewrite?
那是行不通的。尝试这个:
RewriteRule ^/abc/xyz/(.+)$ /abc/xyz?id=$1