I searched the forums and could not find any tutorials or information on extentionless URLs if someone can please do a tutorial on it I would be very grateful or link a tutorial (that includes cPanel) that would be just as appreciated.
I searched the forums and could not find any tutorials or information on extentionless URLs if someone can please do a tutorial on it I would be very grateful or link a tutorial (that includes cPanel) that would be just as appreciated.
Tutorial section is not for asking question/help.No problem, i have moved this thread to programing help![]()
This is achieved through .htaccess and mod_rewrite.
http://en.wikipedia.org/wiki/Mod_rewrite (mainly the links at the bottom)
I think this is right:
RewriteEngine on
RewriteRule ^/([a-zA-Z0-9_-]+$ /$1.php
This means, take all characters a to z A to Z and '-' and '_' between the first '/' (after http://www.yoursite.com) and the end of the url and rewrite it as those same characters with .php at the end.
Don't give up, mod_rewrite is really really tricky![]()
Last edited by garrettroyce; 04-30-2009 at 10:24 PM.
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer
sorry, titat, i thought i could ask for a tutorial guess not :D, garrettroyce, thanks so much you're so helpful, i would give you more reputation but i have to spread it around a bit lol
ok i found the htaccess file but i dont know how to edit it to insert that codeis there a way to add that through cpanel? or some php script?
Last edited by garrensilverwing; 05-01-2009 at 12:07 AM.
Content negotiation is designed to do exactly what you want. Add:to your .htaccess (the "+" means merge the options rather than replace them; read about the Options directive for details).Code:Options +MultiViews
"ok i found the htaccess file but i dont know how to edit it to insert that codeis there a way to add that through cpanel? or some php script?"
Download it to your pc and use text editors like notepad or something...
For extension less urls, can't you just create a directory and put an index.html in it?
Then when you goto http://www.yoursite.com/nameofyourdirectory
you'll get to see the contents of index.html
Why do you like to have extension less urls?
Last edited by Teensweb; 05-01-2009 at 05:31 AM.
Last edited by garrensilverwing; 05-01-2009 at 10:44 AM.
cPanel editor should work as well. Sometimes there's a problem with the differences in the way that *nix and Windows encode files, especially newlines.
@mission I've never heard of using this before, thanks for the tip
I prefer mod_rewrite simply because it has many other functionalities and learning regex is never bad :P
For example you can make index.php?view=home&userid=3423 look like home/user3423
Last edited by garrettroyce; 05-01-2009 at 01:28 PM.
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer
Each does what it was designed to do fairly well. mod_rewrite and content negotiation have some overlap of function, but each for a different purpose. When it comes to type-via-file-extension agnosticism (which is the Right Thing to Do© in URIs), only content negotiation cuts the mustard. There's no longer a need to specify in a URI whether each page is stored as static HTML, a script or something else entirely, which is not easy to do with mod_rewrite. You can change the file type of a resource (page, image &c) without having to make any other changes. It also obviates the need for "choose a language" links in many cases.
If you want your URI and filesystem hierarchies to be different from each other, however, only mod_rewrite will do.
Yes, but where content negotiation lacks is in query strings, which would be the next logical step in development of a user friendly URI. Even if your user is savvy enough to realize your site is using PHP or ASP.NET or any other technology, they probably won't remember site?this=123423&that=324&next=4212314 and unless you want to make one file for every single page you will ever have, mod_rewrite is the only tool to properly accomplish this. And why set up your site one way, knowing full well that you will probably have to change it later?
gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer