Jump to content

extensionless urls?


SecretAgentRege

Recommended Posts

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!
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 +FollowSymlinks
RewriteEngine on
RewriteRule ^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 helps
Cheers
Mark
Link to comment
Share on other sites

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..
Link to comment
Share on other sites

[!--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.
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.