Jump to content

URL use "/" instead of "?" to send variables


rahulephp

Recommended Posts

Hi,

In normal php, We use ?id=123 to send variable through URL.

 

So, the URL would be www.example.com/page.php?id=123 and then we use $_REQUEST['id'] to receive the variable on another page.

 

But my question is, if I use "/" instead of "?" (Ex: www.example.com/page.php/id/123), then how to receive the "id" on page.php.

 

$_REQUEST['id'] doesn't works in this case.

 

Thank you in advance

 

Link to comment
Share on other sites

Your question isn't php related. You use an Apache module called mod_rewrite to rewrite urls from the form www.example.com/page.php/id/123 back to www.example.com/page.php?id=123, php then receives this data in its usual manner.

 

We have a mod_rewrite board here.

Link to comment
Share on other sites

Also, the URL you suggested www.example.com/page.php/id/123 is not a very SEF URL. The biggest reason to rewrite like that is for SEO.

 

The first problem is 'page.php', another reason to rewrite URL's like this is simplify them and take away extensions like php. 'page.php' means nothing to a user, or a search engine. The second problem is there are no keywords, just an ID. Having an ID is fine, but you should also have keywords, like for example:

 

www.example.com/articles/99/some-article-keywords  to www.example.com/page.php?id=99

 

Notice in the above there is no text 'ID' in the URL, there is no need for that usually, it only makes it longer, more complicated, less clean looking.

 

Another option is to lose the ID number altogether. like this for example:

 

www.example.com/articles/some-article-keywords to articles.php?article=some-article-keywords

 

This looks even cleaner and shorter. In your PHP script you would then strip the - from the article name, and do a lookup in the database for an article that matches that name, then show it on the page.

 

 

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.