rahulephp Posted June 21, 2010 Share Posted June 21, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/205394-url-use-instead-of-to-send-variables/ Share on other sites More sharing options...
trq Posted June 21, 2010 Share Posted June 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205394-url-use-instead-of-to-send-variables/#findComment-1074882 Share on other sites More sharing options...
the182guy Posted June 21, 2010 Share Posted June 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205394-url-use-instead-of-to-send-variables/#findComment-1074913 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.