1

i'm replacing this

localhost/load.php?code=foo 

with this

localhost/foo 

using this htaccess code

RewriteRule ^(\w+)$ ./load.php?code=$1 

works pretty good! but what about including other get tag in the same URL like

localhost/load.php?user=foo&code=foo 

replaced it with htaccess to be like

RewriteRule ^(\w+)$ ./load.php?user=$1&code=$1 

but doesn't work as well! so what is the correct htaccess code to do this?

1
  • You're right, but this one worked ^(\w+)/(\w+)/?$ adding the question mark before the dollar sign, Thanks! Commented Sep 13, 2013 at 8:51

1 Answer 1

1

Depending on your other RewriteRules you might want to use a catch-all rule with the QSA (QueryStringAppend) flag.

The QueryString is the part after ? so user=foo&code=foo.

If you have a rule that says:

RewriteRule ^(.*)$ load.php?__path=$1 [QSA] 

And you call:

my.domain.com/page/sub?foo=bar&baz=ipsum 

load.php will get the following GET:

__path = page/sub foo = bar baz = ipsum 

With a rule like this you can handle any URL.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.