Jump to content

[SOLVED] URL Rewrite with 2 Parameters


JasonO

Recommended Posts

Hi,

 

My question is exactly like the question here: http://www.phpfreaks.com/forums/index.php/topic,220713.0.html

 

Unfortunatly it is solved and I can't post in that topic. The thread author originally had a problem with what was given to him, but then he just said he fixed it without actually posting what he done. I don't know how, but for some reason it doesn't work for me either (get 404 page not found error). I've tried contacting the thread author about a solution but nothing yet.

 

Basiclly I currently have this in my htaccess file

RewriteEngine On
RewriteRule ^([^/\.]+)?$ index.php?p=$1 [L]

 

This allows me to have http://domain.com/home the same as having http://domain.com/?p=home

 

However, I need to have more parameters in the URL which I want to have like http://domain.com/home/login for example. The hidden URL would then be along the lines of http://domain.com/?p=home&p2=login

 

I've tried finding out what each symbol means and playing around but I just get 404 errors or server errors when I try them.

 

Where am I going wrong?

 

Thanks,

Jason

Link to comment
Share on other sites

OK, I've got it kinda working I believe.

 

I can get the two parameters from a URL like http://domain.com/site/login and also 1 parameter if a second is not given from say http://domain.com/site/.

 

However, If I miss the trailing slash on the end of the URL off (so like http://domain.com/site), I get a 404. How would I go about geting around that.

 

This is what I have as my rule.

 

RewriteRule ^([^/\.]+)?/([^/\.]+)?$ /index.php?p=$1&p2=$2

 

Thanks.

 

Edit - Done it :)

 

This is the Rewrite Rule I use to pass 2 parameters into a page

 

RewriteRule ^([^/\.]+)/?([^/\.]+)?$ /index.php?p=$1&p2=$2

 

Will allow URL's like

 

http://site.com/user/login » http://site.com/index.php?p=user&p2=login

http://site.com/user » http://site.com/index.php?p=user

http://site.com » http://site.com

 

It will pass the parameters on so on the server.

 

Thanks anyway guys! I hope this post helps others. Feel free to PM me if you get stuck, and have a problem exactly like this :)

 

Regards,

Jason

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.