Question:
In web development, how would one create a URL like example.com/example/ rather than example.com/example.html?
anonymous
2008-01-26 00:42:26 UTC
I constantly see website addresses which end without any sort of file extension (so something like "example.com/example/" rather than "example.com/example.html"). So, for a relatively inexperienced web developer, how does one remove the file extension from the end of the URL? Is there just a folder in the address which "/example/" would be referring to (like "example.com would automatically go to example.com/index.html)? Thanks in advance!
Four answers:
astralkid
2008-01-26 00:51:54 UTC
Generally, a web server needs a default extension. HTML, PHP, ASP, etc...they need something. If you have your default page set to index.html, and in that /example/ folder there is an index.html, then the web server will understand the directory contents, as well as /example/index.html



It's sort of understood by the web server..kinda hard to explain. I hope this helps. :)
shanni
2008-01-26 00:48:39 UTC
The 2nd 'example' in "example.com/example/" actually refers to a subdirectory and not a webpage like "example.html". In the first URL, the page opened is usually index.html or index.htm.
lois
2016-05-28 12:23:04 UTC
I have my own server at home, which runs all those services you mentioned. That being said, I've always used GoDaddy for purchasing names and DNS services. I've also used their hosting services in conjunction with sites I built for other people. US-based support, and fast updates when needed. Regardless of what you're looking for, try to find a company that (a) offers both Windows and Linux based servers, and (b) offers the services ala carte, so you don't get stuck paying for things you don't need.
Allan C
2008-01-26 10:24:52 UTC
If your web server has Apache installed and if you have access to the .htaccess file.



Open up the .htaccess file and add this:



RewriteBase /

RewriteRule ^(.*)/$ $1.html [L]



So in your example if you access: http://www.example.com/example/



(must have trailing slash)



it will really be loading:

http://www.example.com/example.html

on the server(behind the scenes).



Remember that you need to make all of your links and image calls to be absolute. Example:

or they will not load correctly.





The alternative to this, which may be easiest, is to create actual folders.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...