-1

I want to convert this url

http://ts.thebenamorgroup.com/g2g/category.php?cate=mens

to:

http://ts.thebenamorgroup.com/g2g/category/cate/mens/   

I have this rule but it doesnt work:

Options +FollowSymLinks
RewriteEngine on
RewriteRule category/cate/(.*)/ category.php?cate=$1
RewriteRule category/cate/(.*) category.php?cate=$1

3 Answers3

0

You have the logic backwards:

RewriteRule category/cate/(.*)/ category.php?cate=$1
RewriteRule category/cate/(.*) category.php?cate=$1

This will attempt to rewrite category/cate/mens/ into category.php?cate=mens

You can't just reverse it though, because RewriteRule can't operate with query strings, so you need to use RewriteCond as well:

RewriteCond %{QUERY_STRING}     cate=(.*)
RewriteRule /category.php       category/cate/%1

Note the use of %1 to refer to the back-reference in RewriteCond (rather than $1 for a backref in RewriteRule)

fukawi2
  • 5,494
0
RewriteCond %{QUERY_STRING} cate=(.*)
RewriteRule g2g/category.php g2g/category/cate/%1? [L]

This will do exactly what you want. Notice the "?" in RewriteRule stops the query string (?cate=mens) being appended again.

Knoxy
  • 58
0

on https://stackoverflow.com/questions/17535520/rewriterule-doesnt-work @JonLin answer my issue and it works, i post here for if somebody need it

Options +FollowSymLinks
RewriteEngine on
RewriteBase /g2g/

RewriteRule ^category/cate/(.+?)/?$ category.php?cate=$1 [L]

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /g2g/category\.php\?cate=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /g2g/category/cate/%2?%3 [L,R=301]