2

试图重写具有多个参数且其中一个参数包含多个单词(提交时以空格分隔)的页面的 URL。

这将是 URL:www.ABCD.com/store/itemsDescr.php?categ=headbands&id=123&name=brown%20with%20black

我希望 URL 显示如下:www.ABCD.com/store/headbands/123/brown-with-black

我试过这个,但没有奏效:

RewriteCond %{QUERY_STRING} ^categ=([^&]+) [NC,OR]
RewriteCond %{QUERY_STRING} &categ=([^&]+) [NC]
RewriteRule ^store/itemsDescr\.php$ $0/%1

RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC,OR]
RewriteCond %{QUERY_STRING} &id=([^&]+) [NC]
RewriteRule ^store/itemsDescr\.php/[^/]+$ $0/%1

RewriteCond %{QUERY_STRING} ^name=([^&]+) [NC,OR]
RewriteCond %{QUERY_STRING} &name=([^&]+) [NC]
RewriteRule ^store/itemsDescr\.php/([^/]+/[^/]+)$ http://www.ABCD.com/store/$1/%1/? [L,QSA,NC]

任何帮助将非常感激!

注意:在我要实施这条规则之前,我已经为另一个页面准备了这条规则,以防它产生冲突:

    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]
4

1 回答 1

1

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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} !-f
RewriteRule ^(store)/([^/]+)/([^/]+)/ /$1/itemsDescr.php?categ=$2&id=$3 [L,QSA,NC,NE]
于 2013-06-27T08:01:23.720 回答