Page 1 of 1
faking .htm at the end of every URL while passing variables
Posted: Tue Dec 19, 2006 11:29 pm
by yeehawjared
I'm building a site similar to
http://www.ultimate-guitar.com. Let's digest a sample URL from their site:
http://www.ultimate-guitar.com/tabs/l/
led_zeppelin/
stairway_to_heaven_ver4_tab.htm
I can assume the variables getting passed are something like:
?artistLetter=l
?artist=led_zeppelin
?title=stairway_to_heaven
?version=_ver4
?type=_tab
.htm
I can emulate this via mod_rewrite up to the point where they have "
stairway_to_heaven_ver4_tab.htm" I don't understand how they are keeping these variables separate without something like a / (forward slash) between them. I also don't know how they tack on a .htm on the end of every URL
here is my .htaccess file (note: I don't care about separating out the artistLetter as ultimate-guitar has done. root.php figures out what do do with the variables)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ root.php?artist=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ root.php?artist=$1&title=$2 [L]
</IfModule>
does anyone know how to generate this fake URL and retrieve the variables inside it (
title,
version, and
type) while adding a .htm at the end?
Many thanks guys

Posted: Wed Dec 20, 2006 12:26 am
by Kieran Huggins
Why emulate the poor design decisions of another site when you
could try to make
your own poor design decisions?
Seriously though, as long as you're building it, make it REST-ful! It will make things easier on you in the long run (I promise).
Cheers,
Kieran
Posted: Wed Dec 20, 2006 8:35 am
by yeehawjared
really? I don't think it's that poor of web design. I'm still really curious about the .htm on the ends of URLS - makes for a clean appearance.
also, I think this thread may help lead me in the right direction...
viewtopic.php?t=50794
Posted: Wed Dec 20, 2006 9:13 am
by yeehawjared
figured out the how to fake .htm AND how to pass variables separated by underscores.
http://www.avengex.com/tutorials/188/
Posted: Wed Dec 20, 2006 10:07 am
by Kieran Huggins
Posted: Wed Dec 20, 2006 10:29 am
by yeehawjared
thanks for the links... yeah the whole purpose of this is to create clean URLs.
instead of test.php?artist=jared&title=blah&type=tab&version=1 I'm trying to do:
http://www.test.com/jared/blah_tab_ver1.htm
after finding that tutorial I'll be able to do it. That would be a RESTful approach right?
Posted: Wed Dec 20, 2006 2:38 pm
by Kieran Huggins
Don't stop at just removing the GET variables...It would be
most restful to do away with filenames all together. Part of the idea is to make your site a resource with an API, rather than a directory of files.
Try to structure your URLs conceptually, like
Code: Select all
http://site.com/artists/(artist)
http://site.com/artists/(artist)/albums
http://site.com/artists/(artist)/(album)
http://site.com/artists/(artist)/(album)/buyAtAmazon
http://site.com/albums/(album)/buyAtAmazon
http://site.com/tabs/(songname)
http://site.com/tabs/(songname)/(version)
http://site.com/tabs/(songname)/(version)/print
http://site.com/users/(username)
http://site.com/users/(username)/message
http://site.com/users/(username)/edit
http://site.com/users/(username)/contributions
http://site.com/search/(term)
http://site.com/browse/(filter)
Generally, this is WAY more readable, as well as more flexible.
You would essentially be making it /(type_of_page)/(specifier)/(action)
It's also easier to code this way, as relative links are a lot simpler. Imagine on every TAB page, you could simply link to "print" or "save" or "send" and the song identifier is
already in the URL.
Now THAT's RESTful!
Cheers,
Kieran
Posted: Wed Dec 20, 2006 2:43 pm
by yeehawjared
yeah that kind of structure is what i'm shooting for.
I did get everything working the way I wanted it to:
//test.php:
<?
echo $_GET["artist"] . "<br>";
echo $_GET["title"] . "<br>";
echo $_GET["type"] . "<br>";
echo $_GET["version"] . "<br>";
?>
//.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)/(.*)_(.*)_ver(.*).htm$ test.php?artist=$1&title=$2&type=$3&version=$4 [L]
</IfModule>
if the input URL is:
http://localhost/jared/yellowcard/ocean ... b_ver2.htm
artist = yellowcard
title = ocean_avenue
type = tab
version = 2
I still have to add more RewriteRule conditions, but for the most part I've answered all my questions in the first post. Thanks guys.
Posted: Wed Dec 20, 2006 2:48 pm
by John Cartwright
Considering I am a Zend Framework head, I enjoy their use of handling urls.. Simply put, all requests will be sent to a front controller, in your case a page controller, and let php parse what is happening in the url.
So in your case,
http://localhost/pagename/namevalue/pai ... pairvalue1
would be parsed as pagename.php?namevalue=pairvalue&namevalue1=pairvalue1