【发布时间】:2013-06-23 23:22:42
【问题描述】:
试图重写具有多个参数且其中一个参数包含多个单词(提交时以空格分隔)的页面的 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]
【问题讨论】:
-
But I don't want to redirect.是什么意思? -
这实际上是一个错字。删除那个。我只是希望 URL 看起来对 SEO 更友好...
-
好吧,我会采取行动。 (涉及更多)
-
好的,谢谢。我认为我上面的代码对于我需要的东西来说太复杂了,那就是用 3 个参数重写......
标签: .htaccess url redirect mod-rewrite rewrite