How to set the default website page through htaccess?
Asked Answered
R

4

20

I am currently setting up a website from a client on his hosting account. The website address and for some reason doesn't default to .php files (that is: index.php). If I put index.php and there is no index.html file I receive the following error:

If you feel you have reached this page in error, please contact the web site owner: [email protected] If you are the web site owner, it is possible you have reached this page because: The IP address has changed. There has been a server misconfiguration. The site may have been moved to a different server. If you are the owner of this website and were not expecting to see this page, please contact your hosting provider.

His hosting is a shared hosting on cpanel.

Rattan answered 21/12, 2011 at 18:20 Comment(0)
F
33

Use the DirectoryIndex directive in your .htaccess file

DirectoryIndex index.php
Forcier answered 21/12, 2011 at 18:23 Comment(0)
R
4

The problem was caused by my web-browser cache, as soon as I have cleared my cache it worked!

Rattan answered 22/12, 2011 at 8:26 Comment(0)
S
3

You can set your default page as the directory index using .htaccess file in 2 ways.

First method

DirectoryIndex yourfile.php

Above code will set 'yourfile.php' as the directory index. But this will applies to all sub folders as well and may occur '404' error for some related urls.

Second method

Use this code to set your handler file for the root directory

RewriteEngine on
RewriteRule ^$ /yourfile.php [L]

If you want to set a handler file for the sub folder, use this one

RewriteEngine on
RewriteRule ^subfolder/$ /yourfile.php [L]
Semitic answered 13/11, 2019 at 10:39 Comment(0)
A
2

Try

DirectoryIndex index.php

if that doesn't work you might have to work around it by providing index.html like

<html><frameset rows="*"><frame src="index.php"></frameset></html>

(ofcourse more elaborate)

Aboutface answered 21/12, 2011 at 18:25 Comment(1)
If you already suggest a solution of that sort, frame usage is absolutely useless: just set redirect with corresponding <meta> tag.Amphitheater

© 2022 - 2024 — McMap. All rights reserved.