mod rewrite problem

Tag: apache , url , mod-rewrite , rewrite Author: hacat1 Date: 2009-12-31

I am trying to redirect my pages using URL:

RewriteRule ^(.*)/content/(.*)/?(.*)\.html$ browse.php?s=$1&c=$2&l=$3 [NC,L]

For 2 parameters it works fine but when I passes 3 parameters it merges the 2 and third.

Correct output is as follow (2) parameters:

Array ( [s] => wallpapers [c] => Global_Celebrities [l] => Nicole1);

Merged messed output is here (3) parameters:

Array ( [s] => wallpapers [c] => Global_Celebrities/Kate1 [l] =>);

Thanks in advance.

It would be nice if you accept the answer that answers your question best.

Best Answer

You need to use a more specific pattern. Try [^/]+ instead of .*:

RewriteRule ^([^/]+)/content/([^/]+)\.html$ browse.php?s=$1&c=$2 [NC,L]
RewriteRule ^([^/]+)/content/([^/]+)/([^/]+)\.html$ browse.php?s=$1&c=$2&l=$3 [NC,L]

comments:

Thanks for the prompt reply it works fine..
Thank you guyz you are the life Savior (K) ;)

Other Answer1

Easiest way is to go with 2 rules:

RewriteRule ^(.*)/content/(\w*)\.html$ browse.php?s=$1&c=$2 [NC,L]<br/>
RewriteRule ^(.*)/content/(\w*)/(\w*)\.html$ browse.php?s=$1&c=$2&l=$3 [NC,L]

Note, that I am using "\w" instead of ".", so that "." would be unable to eat "/". It might work with . too, it's just safer with \w.