Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

rjendeavours
Courses Plus Student 4,965 PointsHow do you replace index.html as your "home page".
Hey Guys & Girls,
Just wondering if anyone can give me a heads up on how to change the first page that is loaded by the server. Instead of it being index.html?
Probably such a novice question but any help is greatly appreciated. I was going to just redirect from the index.html but SURELY that is such a BAD thing to do.
I've googled this and apparently an .htaccess file might be the way to go. If so, where does that go? Do you put it in your web directory (exactly where the index.html file would have gone?).
How would one write this file?
Thanks
8 Answers

Kevin Korte
28,149 PointsIt's a fail point because the default browser behavior is to look for an index file, which now doesn't exist. If something funky happens, it doesn't read your .htaccess file, etc, it won't load anything and the user might never come back to your site, cause they think nothing is there.
Instead of redirecting to a page name other than index, I'd use the same rewrite rules you would use to clean a URL, to add the "/welcome" part to it.
You are aware that by default, when a browser loads an index page, it doesn't append the "index" part to the web URL. It's kinda like having a freebie clean URL for that index page.
If you used rewrite rules to add your "/welcome" to the URL of the index file, if the browser didn't read or somehow ignored your .htaccess file, your website still loads without the "/welcome" on the URL. Much better scenario than it just not finding your web page at all.

Kevin Korte
28,149 PointsInstead of explain it, this article http://support.tigertech.net/index-file-names makes it pretty simple. I'm curious though as to why you don't want to use index as the file name? You're adding another potential fail point here. You reason to do this should be a strong one.

rjendeavours
Courses Plus Student 4,965 PointsHi Kevin, thanks for the quick reply.
Two reasons really.
I don't want the url to display "index". I'd prefer "welcome". So www.mywebsite.com/welcome
I'm executing php on that file as the user first comes onto the site, so I would need it to have a .php extension. But I plan to use the tutorial here to rewrite those, to keep the url's clean.
Potential fail point? What do you mean exactly?

rjendeavours
Courses Plus Student 4,965 PointsNicely put. Makes a lot of sense and assuming you are accurate in what you saying, I can't see why I wouldn't agree with you.
How exactly can I make that index file capable of using php then?
Can it be an index.php file? Instead of .html, as I'm pretty sure the browser wouldn't be able to read the php then.
Btw, thanks a lot for your help, truly appreciated.

Kevin Korte
28,149 PointsYou can just call your index file index.php. No problem.
However, browsers do not read PHP. The web server that is serving the files to the browser would have PHP installed on it, and the server would interpret all of the PHP code, and send only the HTML, CSS, and Javascript to the browser.
When the browser hits your webpage, it's going to request the index file by default. The server will return the index file as HTML. If there is PHP in the web file, it'll interpret it all first, than send it to the browser.

rjendeavours
Courses Plus Student 4,965 PointsHi Kevin
Sorry, yes I do know that about the server reading the PHP and displaying only the HTML, CSS, Javascript etc Hence the client side and server side code difference.
Not sure why I put about the browser being able to read Php. However your explanation does help to put things nicely in order of how it all works.
I think you have pretty much answered the question in detail.
Thanks

Kevin Korte
28,149 PointsGood deal man! Wasn't sure how much you knew so I didn't want to glaze over anything too fast. Glad I was able to answer you question and give you another way to accomplish the same thing. Sounds like you're on the right track. Good luck and let me know how it goes.

rjendeavours
Courses Plus Student 4,965 PointsI moved onto more advanced areas of php pretty quick and joining it with javascript via ajax etc, so I have missed a few of the basics. Hence not even knowing how to upload a website properly ha ha.
I've started looking at c++. Really got into building things since joining Treehouse about 6 months ago and knowing nothing about programming.
Mind me asking how long you have been programming?

Kevin Korte
28,149 PointsIt's easy to miss a few things here or there.
I've been coding for about 18 months. Started here 8 months ago. My background is actually in product design, but even then you gotta know how to get your work online. I kinda enjoy the challenge it provides. Web programming is like a target that never stops moving. :)

rjendeavours
Courses Plus Student 4,965 PointsAbsolutely
Will be exciting to see where it all goes in years to come and what programmers are capable of building with new technologies.

Martin Paul Bannister
2,014 PointsYou could apply a redirect to your code - instead of loading up index.php, you can specify a particular page