Search code examples
.htaccess

htaccess rewrite rule to include variable


I'm currently using this rewrite rule

RewriteRule ^([\w-]+)/?$ ../new/index.php?product=$1

which is located in the folder /old to make this

sample.com/old/123

forward to this

sample.com/new/index.php?product=123


I'd like to include another variable in this rule to make this

sample.com/old/123?type=1

forward to this:

sample.com/new/index.php?product=123&type=1

Can someone help me figure this put please?


Solution

  • If you add [QSA] to the end of your RewriteRule, it should pass through any additional query strings to the new URL:

    RewriteRule ^([\w-]+)/?$ ../new/index.php?product=$1 [QSA]