0

I want to create URL re-write rules for following URL in htaccess.

http://example.com/vedios/category/fun/ -> http://example.com/vedios/category.php?cat=fun

http://example.com/vedios/category/fun/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular

http://example.com/vedios/category/fun/?show=popular&page=2 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=2

http://example.com/vedios/category/fun/comedy/ -> http://example.com/vedios/category.php?cat=comedy

http://example.com/vedios/category/fun/comedy/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular

http://example.com/vedios/category/fun/comedy/?show=popular&page=3 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=3

I tried RewriteRule category/([^.]+)/?([^.]+)$ /vedio/category.php?cat=$1&$2 for http://example.com/vedio/category.php?cat=fun&show=popular&page=1 but its not working.

Please tell me what could be the correct URL re-write rules for the above requirements?

djmzfKnm
  • 26,679
  • 70
  • 166
  • 227

2 Answers2

4

The query is not part of the URL path that’s checked within the RewriteRule directive. You would need a RewriteCond directive to do that.

But you just need to set the QSA flag to get the initial query string appended to the new one:

RewriteRule category/([^.]+)/$ /vedio/category.php?cat=$1 [QSA]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

My regexp for category script:

/vedio/category/([^.]+)/\?([^.]+)$

It depends if mod_rewrite is evaluating all your URL (server + port + path) or just the path to your script.

sourcerebels
  • 5,140
  • 1
  • 32
  • 52
  • The `RewriteRule` directive just tests the URL path. If used in a .htaccess file, the contextual per-directory prefix is stripped before testing and appended after applying a rule. – Gumbo Jul 06 '09 at 18:09