问题描述
我一直在互联网上寻找这一点,并找到了许多关于如何通过 htacces 重写 url 的清晰文档.我已经知道 htacces 现在可以工作了,但是我的特定 url(s) 不会改变.我尝试过的所有示例都不起作用.希望这里有人可以帮助我.
I have been looking all over the internet for this and found many clear documents on how to rewrite a url via htacces. I've gotten so far that htacces is working now, but my specific url(s) won't change. All kind of examples I have tried do not work. Hope someone here can help me with this.
这是我的网址:
http://www.stamps-as-a-gift.com/category.php?cat1=Holland&cat2=Water&cat3=Vissen&cat4=Dolfijnen
不,我希望它被视为:
http://www.stamps-as-a-gift.com/category/Holland/Water/Vissen/Dolfijnen
我喜欢这个,因为它更容易记住我读过它也对 SE 更友好.
I like this because it is easier to remember en I have read it's also more SE friendly.
我希望这个选项对我来说是可能的..谢谢!
I hope this option is possible for me..thanks!
我的代码不起作用:
RewriteEngine on
RewriteRule ^(cat1|cat2|cat3|cat4)/([^/.]+)/([^/.]+)/([^/.]+)$ category.php?cat=$1&cat2=$2&cat3=$3&cat4=$4
另外 - 每次尝试后我都需要重新启动 apache 吗?
Also - do I need to restart apache after every new try ?
推荐答案
你需要在你的 root .htaccess 中使用这个规则:
You need to use this rule in your root .htaccess:
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)&cat2=([^\s&]+)&cat3=([^\s&]+)&cat4=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/%2/%3/%4? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)&cat2=([^\s&]+)&cat3=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/%2/%3? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)&cat2=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/%2? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+category\.php\?cat1=([^\s&]+)\s [NC]
RewriteRule ^ category/%1/? [R=302,L]
RewriteRule ^category/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ category.php?cat1=$1&cat2=$2&cat3=$3&cat4=$4 [L,QSA,NC]
RewriteRule ^category/([^/]+)/([^/]+)/([^/]+)/?$ category.php?cat1=$1&cat2=$2&cat3=$3 [L,QSA,NC]
RewriteRule ^category/([^/]+)/([^/]+)/?$ category.php?cat1=$1&cat2=$2 [L,QSA,NC]
RewriteRule ^category/([^/]+)/?$ category.php?cat1=$1 [L,QSA,NC]
这篇关于url-rewriting htacces - 如何重写我的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!