本文介绍了包含多字串多个参数(mod_rewrite的)重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 试图重写的页面具有多个参数和参数之一包含多个字(当提交由空格分隔)的URL。 这将是网址: www.ABCD.com/store/itemsDescr.php?categ=headbands&id=123&name=brown%20with%20black我想的网址显示是这样的:www.ABCD.com/store/headbands/123/brown-with-black 我想这一点,但它没有工作: 的RewriteCond%{QUERY_STRING} ^ CATEG =([^&功放;] +)[NC,OR]的RewriteCond%{QUERY_STRING}&放大器; CATEG =([^&功放;] +)[NC]重写规则^店/ itemsDescr \ .PHP $ $ 0 /%1的RewriteCond%{QUERY_STRING} ^ n =([^&功放;] +)[NC,OR]的RewriteCond%{QUERY_STRING}和ID =([^&安培;] +)[NC]重写规则^店/ itemsDescr \的.php / [^ /] + $ $ 0 /%1的RewriteCond%{QUERY_STRING} ^名=([^&功放;] +)[NC,OR]的RewriteCond%{QUERY_STRING}&放大器;名称=([^&功放;] +)[NC]重写规则^店/ itemsDescr \的.php /([^ /] + / [^ /] +)$ http://www.ABCD.com/store/$1/%1/? [L,QSA,NC] 任何帮助将是非常美联社preciated!注:在这个规则我想要实现,我已经有这等规则的另一页,在情况下,它可以产生冲突: 的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S / +(店)/index\.php\?categ =([^ \ s] +) NC]重写规则^ / 1%/ 2%? [R = 301,L]的RewriteCond%{} REQUEST_FILENAME!-f重写规则^店/(.+?)/?$ /store/index.php?categ=$1 [L,QSA,NC] 解决方案 到的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在的.htaccess $ DOCUMENT_ROOT 目录下: 选项+了FollowSymLinks -MultiViews#开启mod_rewrite的上RewriteEngine叙述上的RewriteBase /的RewriteCond%{QUERY_STRING} ^ CATEG =([^&安培;] +)安培;编号=([^&安培;] +)及名称=([^&安培;] +)$ [NC]重写规则^(店)/itemsDescr\.php$ / $ 1/1%/ 2%/ 3%? [R = 302,L,NC,NE]重写规则^(存储)/([^ \ s] +)\ S([^ \ s] +)/ $ 1 / $ 2- $ 3 [R = 302,L,NC]重写规则^(存储)/([^ \ s] +)\ S(+)/ $ 1 / $ 2- $ 3 [L,NC]的RewriteCond%{} REQUEST_FILENAME!-f重写规则^(存储)/([^ /] +)/([^ /] +)/ /$1/itemsDescr.php?categ=$2&id=$3 [L,QSA,NC,NE] Was trying to rewrite the URL of a page that has multiple parameters and one of the parameters contains multiple words (separated by spaces when submitted). This would be the URL: www.ABCD.com/store/itemsDescr.php?categ=headbands&id=123&name=brown%20with%20blackI would like the URL to show like this:www.ABCD.com/store/headbands/123/brown-with-blackI tried this, but it did not work:RewriteCond %{QUERY_STRING} ^categ=([^&]+) [NC,OR]RewriteCond %{QUERY_STRING} &categ=([^&]+) [NC]RewriteRule ^store/itemsDescr\.php$ $0/%1RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC,OR]RewriteCond %{QUERY_STRING} &id=([^&]+) [NC]RewriteRule ^store/itemsDescr\.php/[^/]+$ $0/%1RewriteCond %{QUERY_STRING} ^name=([^&]+) [NC,OR]RewriteCond %{QUERY_STRING} &name=([^&]+) [NC]RewriteRule ^store/itemsDescr\.php/([^/]+/[^/]+)$ http://www.ABCD.com/store/$1/%1/? [L,QSA,NC]Any help would be much appreciated!NOTE: Before this rule I want to implement, I already have this other rule for another page, in case it can create conflict: RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(store)/index\.php\?categ=([^\s]+) [NC]RewriteRule ^ /%1/%2? [R=301,L]RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^store/(.+?)/?$ /store/index.php?categ=$1 [L,QSA,NC] 解决方案 Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:Options +FollowSymLinks -MultiViews# Turn mod_rewrite onRewriteEngine OnRewriteBase /RewriteCond %{QUERY_STRING} ^categ=([^&]+)&id=([^&]+)&name=([^&]+)$ [NC]RewriteRule ^(store)/itemsDescr\.php$ /$1/%1/%2/%3? [R=302,L,NC,NE]RewriteRule ^(store)/([^\s]+)\s([^\s]+)$ /$1/$2-$3 [R=302,L,NC]RewriteRule ^(store)/([^\s]+)\s(.+)$ /$1/$2-$3 [L,NC]RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(store)/([^/]+)/([^/]+)/ /$1/itemsDescr.php?categ=$2&id=$3 [L,QSA,NC,NE] 这篇关于包含多字串多个参数(mod_rewrite的)重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 21:16