Jump to content

Adding Second Variable To My Rewrite String


sintax63

Recommended Posts

Hello forum -

 

I have a RewriteRule that I have been using for a while which has served me well:

 

RewriteRule ^([^\/]+)\/?$ main/?login=$1

 

This allows me to to take

 

http://mydomain.com/main/index.php?login=username

 

... and rewrite it to the following:

 

http://mydomain.com/username

 

As I said, all has been well until I started coding up my calendar page which has an additional variable ($event) tacked on to the URL. This is the actual, unwritten URL structure

 

http://mydomain.com/main/calendar/view.php?login=username&event=2

 

that I need to rewrite back to

 

http://mydomain.com/username/calendar/view.php?event=2

 

I have currently come up with the following RewriteRule

 

RewriteRule ^([^\/]+)\/calendar\/view.php([0-9]+)?$ main/calendar/view.php?login=$1&event=$2

 

which works fine for the login variable but it doesn't pass the event one. This will pull up the web page correctly, URL wise, but won't acknowledge the $event variable at all.

 

I have read through several tutorials already trying to figure it out myself but have yet to get it working. Would anyone be able to show me what I'm doing wrong?

 

Thanks in advance!

After much digging and reading, I came up with this solution...

 

RewriteRule ^([^\/]+)\/calendar\/view.php?$ main/calendar/view.php?login=$1 [QSA]

 

which basically added the [QSA] to the end of the rule. Not sure if its the best way, but it works for now!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.