Using .htaccess to clean up hyperlinks and urls...
Hi,
A few years ago (before I knew enough to start coding on my own) a friend of mine set up one of my websites so that I never had to use file extensions in my hyperlinks.
What the server would do in the absence of an extension is cycle through a list of favored ones (specified by me) until it found a match. In other words, if I'm linking to just "/contact" (no extension) then the server would search the target folder for "contact.php" (assuming .php is first on my list of extensions to search for) and failing that, it'll search for the next extension (.html); and so on...
The purpose is merely elegance, nothing more; I find that linking to "/contact" looks better than linking to "/pages/contact.html" (and also gives less away about the BTS structure of the site).
I'm already using the following code (provided by one of you superheroes a couple of months back) to remove /pages from the url.:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/pages/
RewriteRule ^(.*)$ /pages/$1
If someone could tell me how to edit this so that I don't even have to specify extensions (because the server will know what extensions to search for, in order) then the UX would be so clean you could eat off it (all links would be simply /contact, /about, /portfolio, etc.)
I'm sure I could achieve the same results by creating a subfolder for each page, putting an index file in each subfolder and linking to said subfolder rather than a file... but talk about unnecessary bloat, if the same can be achieved with a simple addition to the .htaccess file.
Can it?
Thanks!
