我有一个页面重定向网址,如下所示,包含多个参数。
从该URL我将获取所有参数值以从数据库中获取数据。
因此,当我加载此页面时,我需要显示最友好的URL,如下所示。在该URL中应该只包含product_id的值,我正在使用我的重定向URL
我试图像下面那样重写此网址。但是因为我无法使用参数“categoryId”和“keyword”
重写^ /([a-zA-Z0-9 / - ] +)。htm /search.php?layout=details&view=product&Keyword=$3&CategoryId=$2&product_id=$1 last;
请有人帮我成功完成..
此致
VIGNESH KUMAR K
答案 0 :(得分:1)
试试这个伴侣,
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/search\.php\?layout=details&Keyword=([^&]*)&view=product&CategoryId=([^&]*)&product_id=([^&]*) [NC]
RewriteRule ^ /%2/%3/%1? [L,NE,R=302]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /search.php?layout=details&Keyword=$2&view=product&CategoryId=$3&product_id=$1 [L,QSA]
原始网址:
重写的网址:
更新1:
现在已经在上面的代码中添加了[QSA],以便附加查询字符串以便进行检索 使用PHP $ _GET
的动态参数
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa
更新2:
编辑.htaccess代码以生成关键字和CategoryId动态