我一直在网上寻找这个,并找到了很多关于如何通过htacces重写网址的明确文件。到目前为止,我已经知道htacces现在正在工作,但我的具体网址不会改变。我尝试过的各种例子都不起作用。希望有人可以帮助我。
这是我的网址:
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友好。
我希望这个选项对我来说是可能的......谢谢!
我的代码无效:
RewriteEngine on
RewriteRule ^(cat1|cat2|cat3|cat4)/([^/.]+)/([^/.]+)/([^/.]+)$ category.php?cat=$1&cat2=$2&cat3=$3&cat4=$4
另外 - 每次尝试新手后我都需要重启apache吗?
答案 0 :(得分:1)
您需要在根目录中使用此规则.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]