SecretAgentRege Posted March 23, 2006 Share Posted March 23, 2006 Hello,I was curious how sites like wikipedia (running in php) has urls like "http://en.wikipedia.org/wiki/George_washington" without any extension on them. I understand php.net's urls and 404-error searching and redirect theory, which is cool, but I don't have the knowledge on how wikipedia went about these urls?I'm not necessarily asking for a how-to, just what the process is called and how to go about it/get more information.Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/ Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 I don't know for fact, but I'm going to guess that they use Apache's URL ReWrite engine. IIS has a similar extension now, but I don't think it's quite as powerful. Look it up on the web if you're really curious. Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/#findComment-20001 Share on other sites More sharing options...
SecretAgentRege Posted March 23, 2006 Author Share Posted March 23, 2006 Hmm, yes.I found some additional resources, including [a href=\"http://www.webmasterworld.com/forum92/5610.htm\" target=\"_blank\"]http://www.webmasterworld.com/forum92/5610.htm[/a] which better explains the apache rewrite et al.However, this got me thinking, and though it seems far-fecthed I might as well pose the question: Would it be possible to have a page such as 'http://www.dummy.com/people/person.php?id=345' show as 'http://www.dummy.com/people/George_Washington/' in the address bar?Thanks,Regis Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/#findComment-20006 Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 I suppose... that would be kinda tricky tho. Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/#findComment-20011 Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 what youre on about is Apache's Mod_rewrite, which literally does what it says on the tin - rewrites URL's. In addition, the rewriting is done behind the scenes, so the URL remains intact in its friendly format, but the server is actually reading the right file with the right params.getting the right results has been time consuming and full of 500 internal server errors, so be prepared to get the Regex manual out. it's not horribly difficult though. Here's how my link used to look:[a href=\"http://www.thedinnertimes.com/news/article.php?id=64\" target=\"_blank\"]http://www.thedinnertimes.com/news/article.php?id=64[/a]here's how you can get to it now:[a href=\"http://www.thedinnertimes.com/news/article64.htm\" target=\"_blank\"]http://www.thedinnertimes.com/news/article64.htm[/a]here's the 3 lines in my .htaccess file that does it:[code]Options +FollowSymlinksRewriteEngine onRewriteRule ^news(/[0-9]*/[0-9]*)?/article([0-9]*).htm(l)?$ news/article.php?id=$2 [L][/code]the rewrite rule is in 2 or 3 parts. the first part is the regex match depending on what URL was entered. the second part is the file and parameters that it relates too. the third (optional) is any additional instructions.it does take a while to get your head around it all, but the examples i gave you should give you an idea. otherwise, just put 'mod_rewrite' into google and you'll find plenty of examples.hope that helpsCheersMark Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/#findComment-20019 Share on other sites More sharing options...
SecretAgentRege Posted March 23, 2006 Author Share Posted March 23, 2006 Thanks for the great post redbullmarky!I think I'm getting the mod_rewrite, but, as it seems, it would be impossible to rewrite the url '[b]http://www.dummy.com/people/person.php?id=345[/b]' to '[b]http://www.dummy.com/people/George_Washington/[/b]' because the string 'George_Washington' doesn't display in the URL in the firstplace. however, with an extra column in the database to index and pull George's info, we could have strings (say titles or names) instead of id number's for links and database indexing; something like '[b]http://www.dummy.com/people/person.php?id=George_Washington[/b]' rewritten to '[b]http://www.dummy.com/people/George_Washington/[/b]' and with php.net's 404-searching technique error-catch variants of 'George_Washington' and redirect to the correct url.That make sense? I think I'm getting the technique process.. Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/#findComment-20021 Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 [!--quoteo(post=357654:date=Mar 23 2006, 04:31 PM:name=SecretAgentRege)--][div class=\'quotetop\']QUOTE(SecretAgentRege @ Mar 23 2006, 04:31 PM) [snapback]357654[/snapback][/div][div class=\'quotemain\'][!--quotec--]However, this got me thinking, and though it seems far-fecthed I might as well pose the question: Would it be possible to have a page such as 'http://www.dummy.com/people/person.php?id=345' show as 'http://www.dummy.com/people/George_Washington/' in the address bar?[/quote]in a word, yes and no. yes if you want to bring your server to a halt whilst it tries matching your URLs, otherwise, no.the best way to do the wikipedia type thing, using your example, would be to look outside the box a little. in many cases, people use things like 'id=345' to refer to the key of the record in the database. but if your url accepted, for example, 'topic=George_Washington', then it's just a simple rewrite.[code]RewriteRule ^people/([A-Za-z0-9\_)$ people/person.php?topic=$1 [L][/code]hope that helps[!--quoteo(post=357671:date=Mar 23 2006, 05:11 PM:name=SecretAgentRege)--][div class=\'quotetop\']QUOTE(SecretAgentRege @ Mar 23 2006, 05:11 PM) [snapback]357671[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks for the great post redbullmarky!I think I'm getting the mod_rewrite, but, as it seems, it would be impossible to rewrite the url '[b]http://www.dummy.com/people/person.php?id=345[/b]' to '[b]http://www.dummy.com/people/George_Washington/[/b]' because the string 'George_Washington' doesn't display in the URL in the firstplace. however, with an extra column in the database to index and pull George's info, we could have strings (say titles or names) instead of id number's for links and database indexing; something like '[b]http://www.dummy.com/people/person.php?id=George_Washington[/b]' rewritten to '[b]http://www.dummy.com/people/George_Washington/[/b]' and with php.net's 404-searching technique error-catch variants of 'George_Washington' and redirect to the correct url.That make sense? I think I'm getting the technique process..[/quote]absolutely spot on. there's also nothing wrong with having a 'suggestion' page with names and a summary if whatever is typed matches more than one person, and then letting the user decide who they're after. Quote Link to comment https://forums.phpfreaks.com/topic/5607-extensionless-urls/#findComment-20022 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.