Change default page from index.php to index.html - php

Simple as the question. I want to change my website's default page from index.php to index.html. I don't know if my server (000webhost.com, while website is under development) uses Apache, but I've changed the .htaccess file, and added DirectoryIndex index.html index.php. Still not working, though.
When the website loads, it loads randomwebsitename12345.com. If I add /index.html to the string, then the page loads fine, as it should. If I remove the .php file from my server, then the website loads index.html.
Any ideas?

Why not just remove index.php from the .htaccess file?

You can use the following rewrite rule to set index.html as your homepage :
Add this before other rules in your htaccess :
RewriteEngine on
RewriteRule ^$ /index.html [L]

Related

.htaccess - redirect everything

I am trying to get a landing page to work while I am doing scheduled updates on my site.
So basically all my original files will still exist in the directory including my index.php file but I've added another index1.html, so whenever I do an update I just want to be able to un-comment a line in my .htaccess file and everything will redirect to the landing page.
In my .htaccess file I have:
Options -MultiViews
RewriteEngine on
RewriteRule ^(.*)$ index1.html?path=$1 [L,NC,QSA]
This works for me in so far as any file or sub-directory I go to like example.com/whatever will redirect but example.com will still go to the original index.php which is what I want to be updating.
This line did exactly what I wanted:
DirectoryIndex index1.html

How to open an index page into a subdirectory without adding /index.html

Simple question, let's pretend I have the following path:
http://example.com/subdir/index.html
I would like to be able to open that index.html page by typing this in the browser:
www.example.com/subdir
and hit enter to have the browser load its included index.html page.
Is that possible?
My goal is to have a few subdirectories with the same root domain (example.com) and be able to open the index.html pages of each subdirectory without having to add /index.html at the end.
Thanks so much!
For sub folders only put this in main root .htaccess file :
RewriteEngine On
RewriteRule ^(.*)/index([\.html]*)$ /$1 [R=302,L]
For entire website change it to this :
RewriteEngine On
RewriteRule ^(.*)index([\.html]*)$ /$1 [R=302,L]
So , any request with index or index.html will be removed .
Note : clear your browser cache then test it , if Ok change 302 to 301 to get permanent redirection
If you server is running Apache, just create an .htaccess file (if you haven't already) and add this line at the top of the file:
DirectoryIndex index.html

HTML to PHP redirect for website in my root folder?

I have recently moved my website to wordpress. I need to redirect my .html to .php. With my website being in the root folder, I do not want any redirects in the .htaccess to affect my sub folders with other sites in them.
Is there a rule to just redirect them for my specific website?
Using the .htaccess should be the best way.
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://mt-example.com/`
# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/`
# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html
Also here is a video on how to create the .htaccess and edit
Video creaton and edition of .htaccess in wordpress
At the top of your root htaccess, put this :
RewriteEngine on
RewriteRule ^(.+)\.html$ /$1.php [L,R]
This will redirect all html requests to php eg : /file.html to /file.php R is a temporary redirect flag, you can change this to R=301 permanent redirect when you are sure the rule is working fine.

Why DirectoryIndex index.php index.html is not working?

I currently use ipage as a host and have a domain pointing to an index.html. However, I need the domain to point to an index.php instead. So I created a .htaccess and only wrote; DirectoryIndex index.php index.html and saved it but it's not working and users are still being directed to index.html. There is one issue and that index.php is inside a folder called "SourceFolder". So I think the server looks for index.php and can't find it.
Your DirectoryIndex directive is fine but you need to route request to correct folder.
Have this code in root .htaccess:
DirectoryIndex index.php index.html
RewriteEngine On
RewriteRule !^SourceFolder/ SourceFolder%{REQUEST_URI} [L,NC]
So your default 'root' directory of the website has a folder in it called SourceFolder, and the index.php file is in there?
If so, then simply do the following inside htaccess.
DirectoryIndex SourceFolder/index.php
This will look for index.php inside SourceFolder.

.htaccess or PHP change url

Currently my .htaccess file reads:
DirectoryIndex dice.php
Dice.php is a loading page which has an iframe in (index.php) which eventually when finished loading breaks the iframe and fills the page. However it fills it as https://example.com/index.php in the url.
I want it to fill as https://example.com/play.
Anyone have any ideas?
Try adding this to your .htaccess file
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^play/?$ index.php [NC,L]

Categories