重定向字符串.htaccess


Redirect String .htaccess

我是.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/xy?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