Bas Schreuder
Bas Schreuder

Reputation: 172

url-rewriting htacces - how to rewrite my link?

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.

This is my urL :

http://www.stamps-as-a-gift.com/category.php?cat1=Holland&cat2=Water&cat3=Vissen&cat4=Dolfijnen

No I would like it to been seen as:

http://www.stamps-as-a-gift.com/category/Holland/Water/Vissen/Dolfijnen

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!

My code that isnt working:

RewriteEngine on
RewriteRule ^(cat1|cat2|cat3|cat4)/([^/.]+)/([^/.]+)/([^/.]+)$ category.php?cat=$1&cat2=$2&cat3=$3&cat4=$4

Also - do I need to restart apache after every new try ?

Upvotes: 1

Views: 66

Answers (1)

anubhava
anubhava

Reputation: 785631

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]

Upvotes: 1

Related Questions