Reputation: 8555
I am a complete noob when it comes to the .htaccess file... What I'm trying to do is check to see if a GET variable exists, ?si=10
, and pass that onto the rewrite, but only if it exists.
RewriteRule ^user/([^/\.]+)/?$ profile/index.php?name=$1
This way when I have say website.com/user/Username/
it goes to, on the server, website.com/profile/?name=Username
instead. But when I add do website.com/user/Account/?si=10
, the server isn't passing the si
variable onto the actually loaded page. Any idea how I would do this? Sorry if I worded this badly..
Upvotes: 1
Views: 1229
Reputation: 5905
You can do it like this:
RewriteCond %{QUERY_STRING} ^si=([0-9]+)$ // replace regex as neccesary
RewriteRule ^user/([^/\.]+)/?$ profile/index.php?name=$1&si=%1
The percentage sign % brings in the match or matches from the rewriteCond(s) and you use the dollar sign as normal for the matches from the rewriteRule. This gives you full control of your query vars, but yes, QSA is simpler.
Upvotes: 1
Reputation: 300855
Try the QSA flag
RewriteRule ^user/([^/\.]+)/?$ profile/index.php?name=$1 [QSA]
From the manual...
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
Upvotes: 4