Set Your Directory Index (Homepage) Using .htaccess
As every web developer knows, the server default for a directory's default file is index.{extension}. Apache is usually set to index.php or index.html. It's a good practice to set your DirectoryIndex setting in your .htaccess file, especially if you're hosting your website on shared hosting. A hosting provider's guidelines could change at any time but your .htaccess file's directive would prevent any problem for you.
Another reason to use this property would be if your website were to go down for maintenance, or a section of your website. Here's how you can use this property.
The Code
DirectoryIndex index.php index.html site-down.php
For maximum performance, we all know we must put our assets on CDN (another domain). Along with those assets are custom web fonts. Unfortunately custom web fonts via CDN (or any cross-domain font request) don't work in Firefox or Internet Explorer (correctly so, by spec) though...
Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices. While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals. Add animation and you've got something really neat. Unfortunately each CSS cube tutorial I've read is a bit...
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
Hello, I have 2 homepages (in the root folder): 1 in French (let’s say bienvenue.html), and 1 in English (let’s say welcome.html).
If i set the English page as default via DirectoryIndex, then Google (.fr) Search Results will display the English (meta) contents – Welcome blablabla – when there’s a match with French search terms…
I also have these 2 lines in htaccess:
Could this be because of this redirection?
Any hint on how to fix this so that the French version is displayed for search results matches in French?
Thanks it works great! :) God bless you…
Or using this:
DirectoryIndex index.htm index.php
That code is an seo friendly way of redirecting your domain to the www version.
For displaying results in French it might be best to display the site in a folder named something like /FR. Read this post by seomozfor more information.
hello m working on a website on which now some pages are coming like page.php?cid=1&pid=5. but in database the category name for id 1 is say demo and the product name for id 5 is say xyz so i want to rewrite my url as page.php/demo/xyz.html. how to do this? please help. is this possible through htaccess file?
sory the url sud b like “page/demo/xyz.html” or “page/demo/xyz”
That’s the one line i was looking for as i want to leave index.html but want to use index.php. Thanks!
Thanks for not explaining the syntax at all. What is index.php, what is index.html, what is site-down.php?
@Alex – If you don’t know what those file extensions are, then you need to do something else instead of showing your ignorance to people trying to learn.
I have a HTML website with a issue:
Some of my web pages appear duplicate:
domain.com/folder/
domain.com/folder/index.html
How to resolve this? plz guide.
I have a issue:
I have a webpage welcome.php
I would like to use .htaccess to write the url into welcome.php?target=abc
How do I do it?
HI!
I have a flash splash page which has a link “http://www.my url.com/subfolder/index.html”. Now I have a Joomla site, I need to redirect the html address to “http://www.my url.com/subfolder/index.php” instead. How do I add the line in .htaccess? I tried to use the redirect in control panel but it did not work. Thank you!
thanks! was trying to find how to set a home page of another php file with htaccess, and found your post.
Question Is :
hello m working on a website on which now some pages are coming like page.php?cid=1&pid=5. but in database the category name for id 1 is say demo and the product name for id 5 is say xyz so i want to rewrite my url as page.php/demo/xyz.html. how to do this? please help. is this possible through htaccess file?
sory the url sud b like “page/demo/xyz.html” or “page/demo/xyz”
Answer Is : write in yr .htaccess file as follows.
the first one
(?([a-zA-Z-_0-9]+)?)
is for demo and second one(?([a-zA-Z-_0-9]+)?)
is for xyz which will be passed to index.php?cate & prodso cate=demo and prod=xyz and use this arguments in yr index.php file by
$_GET["cate"]
and$_GET["prod"]
Regards ,
Mohammad Ziyad
Hi
I’m trying to fix a friends websites. Root domain with independent sub-domains. First website uploaded fine to correct subdomain folder, but second site will only work if loaded into the root directory and other sites now do not work. I think I may have deleted off the .htaccess directory. What do I do?
Just to complement your entry, I used somenthing like
DirectoryIndex maintenance.php
inside a directory named ./maintenance
So it goes ahead and loads the maintenance.php page. No need mentioning any “index.*” page.
Hello
Can I change page name of index.html and replace with any keyword page name like keyword.html.
And that set into directoryindex in htaccess file.
How about set error 404 page, can you help me to create .htaccess??
Thanks for help
In the .htaccess add the following code:
Then create the error doc, 404.htm, in the home directory (or include the file path in the .htaccess file).
In usual, when page loads, the index.php file is displayed on user’s display, but I have a task to make a new homepage, which should be displayed to user. The question is, how can I accomplish the task, so that the user will see newly created homepage index.php? If I need to configure .htaccess, how should I do it?