[英]Rewrite URL with multiple parameters php
I have page redirect URL like below with more than one parameters.我有如下所示的页面重定向 URL,其中包含多个参数。
http://example.com/search.php?layout=details&Keyword=mobile&view=product&CategoryId=1026&product_id=93477 http://example.com/search.php?layout=details&Keyword=mobile&view=product&CategoryId=1026&product_id=93477
From that URL i'm taking all parameter values to take a data from database.从那个 URL 我取所有参数值来从数据库中获取数据。
So when i load this page i need to show URL most user friendly like below.所以当我加载这个页面时,我需要显示最用户友好的 URL,如下所示。 In that URL should contain only the value of product_id which is i'm using my redirect URL
在该 URL 中应仅包含 product_id 的值,即我正在使用我的重定向 URL
http://example.com/93477.htm http://example.com/93477.htm
I have tried to rewrite this URL like below.我试图重写这个 URL,如下所示。 But in that i couldn't use the parameters "categoryId" and "keyword"
但是我不能使用参数“categoryId”和“keyword”
rewrite ^/([a-zA-Z0-9/-]+).htm /search.php?layout=details&view=product&Keyword=$3&CategoryId=$2&product_id=$1 last;重写 ^/([a-zA-Z0-9/-]+).htm /search.php?layout=details&view=product&Keyword=$3&CategoryId=$2&product_id=$1 最后;
Please anyone help me to done it successfully..请任何人帮助我成功完成它..
Regards,问候,
VIGNESH KUMAR K维尼什·库马克
Try this mate ,试试这位朋友
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]
The original URL:原网址:
http://example.com/search.php?layout=details&Keyword=mobile&view=product&CategoryId=1026&product_id=93477
http://example.com/search.php?layout=details&Keyword=mobile&view=product&CategoryId=1026&product_id=93477
The rewritten URL:重写后的网址:
Update 1 :更新 1:
[QSA] has been added in the above code now so that to append the query string in order to retrive dynamic parameters using PHP $_GET
[QSA] 现在已添加到上面的代码中,以便附加查询字符串以便使用 PHP $_GET 检索动态参数
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa
Update 2:更新 2:
Edited the .htaccess code to make Keyword and CategoryId Dynamic
编辑 .htaccess 代码,使 Keyword 和 CategoryId 动态化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.