views:

474

answers:

1

Hey there,

I'm not too inexperienced with ReWrite (not a master either, though) so I was hoping somone might be able to help me.

RewriteRule ^$ index.php?page=home [NC]
RewriteRule ^adm$ index.php?page=adm_home [NC]
RewriteRule ^adm/stats index.php?page=adm_stats [NC]

Above is a snippet of my .htaccess file. As you can see, when someone visits http://www.example.com/adirectory/ it actually calls on index.php?page=home, similarly if someone goes to http://www.example.com/adirectory/adm/ it will still call index.php?page=adm_home within the "adirectory".

What I'm wanting to achieve is this: I want to be able to display alerts on my pages, and to do this I want to simply be able to add alert=n (where n is a number) and thus have the redirect as index.php?page=home&alert=n

However, I can't understand how this can be done, regex is confusing me. Seeking your help.

+5  A: 

You can set the QSA flag to automatically append the originally requested query string to the new one:

RewriteRule ^$ index.php?page=home [L,QSA]
RewriteRule ^adm$ index.php?page=adm_home [L,QSA]
RewriteRule ^adm/stats$ index.php?page=adm_stats [L,QSA]
Gumbo
Dangit, I've been parsing the $_SERVER variables to extract this information myself. +1
Allain Lalonde
This works like a treat! Thanks Gumbo
jakeisonline