Jump to content


Photo

extensionless urls?


  • Please log in to reply
6 replies to this topic

#1 SecretAgentRege

SecretAgentRege
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 23 March 2006 - 04:03 PM

Hello,

I was curious how sites like wikipedia (running in php) has urls like "http://en.wikipedia....rge_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!

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 March 2006 - 04:18 PM

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.

Info: PHP Manual


#3 SecretAgentRege

SecretAgentRege
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 23 March 2006 - 04:31 PM

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...rson.php?id=345' show as 'http://www.dummy.com...rge_Washington/' in the address bar?

Thanks,
Regis


#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 March 2006 - 04:43 PM

I suppose... that would be kinda tricky tho.

Info: PHP Manual


#5 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 23 March 2006 - 04:59 PM

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:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^news(/[0-9]*/[0-9]*)?/article([0-9]*).htm(l)?$ news/article.php?id=$2 [L]

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
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#6 SecretAgentRege

SecretAgentRege
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 23 March 2006 - 05:11 PM

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 'http://www.dummy.com/people/person.php?id=345' to 'http://www.dummy.com/people/George_Washington/' 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 'http://www.dummy.com/people/person.php?id=George_Washington' rewritten to 'http://www.dummy.com/people/George_Washington/' 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..

#7 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 23 March 2006 - 05:14 PM

[!--quoteo(post=357654:date=Mar 23 2006, 04:31 PM:name=SecretAgentRege)--][div class=\'quotetop\']QUOTE(SecretAgentRege @ Mar 23 2006, 04:31 PM) View Post[/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...rson.php?id=345' show as 'http://www.dummy.com...rge_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.

RewriteRule ^people/([A-Za-z0-9\_)$ people/person.php?topic=$1 [L]

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) View Post[/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 'http://www.dummy.com/people/person.php?id=345' to 'http://www.dummy.com/people/George_Washington/' 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 'http://www.dummy.com/people/person.php?id=George_Washington' rewritten to 'http://www.dummy.com/people/George_Washington/' 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.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users