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

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.

Related

Error on using .htaccess

I'm trying to use my .htaccess file but I still can't figure it out what am I doing wrong.
I only want my domain to be yescpol.com.br, and it always comes like this
My .htaccess is inside the folder "porcelanato" and it has this code:
RewriteEngine on
RewriteBase /porcelanato/
I only want my index.php to turn into yescpol.com.br
What am I doing wrong?
The easiest thing to do would be to change the DocumentRoot in the domain configuration or move your files out of that folder and into the root.
If you want to stick with the rewrite method, you will need to add a rule like this.
RewriteEngine On
RewriteRule ^$ /porcelanato [L]
Add this line to the top of your .htaccess file:
DirectoryIndex index.php
Though if this property is set properly on your apache service in httpd.conf (or whatever is serving your pages) this won't have to be added to your .htaccess file.

Change default page from index.php to index.html

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]

Change index.html from root directory to subdirectory

Right now the index.html of my website is loading from the root directory when someone enters www.mydomain.com in their browser, which as I understand it is the default behavior. I want to move all of my website files into a subdirectory (e.g. public) so that when someone loads www.mydomain.com, the index.html file it loads is in the /public/ directory on my server. However, I do not want the URL to change to www.mydomain.com/public. From there, if a link is clicked/, all of the files will be in the public directory. How would I go about achieving something like that
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^((?!public/).*) public/$1 [L,NC]

HTML Directory looking URL

My friend recently told me that I was able to do something like
http://example.com/about/
without having to create a directory and place a index.html inside of it, like this.
http://example.com/about/index.html
How in the world do you do this? I didn't know it was even possible to do unless you created a directory and placed a index.html inside of it, anyway thanks. :)
If you use Apache as WEB server, use .htaccess for you site root directory.
Write following rule here:
DirectoryIndex index.html
Also you can use more than one file here:
DirectoryIndex index.php index.html
In this case first found will be used.
If you don't want to use .htaccess, you can setup same in Apache config file (httpd.conf):
< Directory /foo>
DirectoryIndex index.html
DirectoryIndex index.php
< /Directory>
Here /foo - root directory of your site
Servers like Nginx can allow you to rewrite URLs, so you can place your file wherever you want.
If you use Apache web server then create a file named .htaccess
and write code like below
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?load=$1 [PT,L]
If this code when you type a url like www.example.com/about its doing to open your aboutController
Write aabout in this url http://salopek.eu/content/28/create-a-simple-php-mvc-framework
If you does not use Apache or you want simple solution then then you can just create a folder named about and create a simple index.html or index.php file. Then when you type www.example.com/about
it opens your about\index.html or index.php file
I hope it helps

Load intro page before actual web-page

I need to load single index.html file before actual index.php I have on server.
I have:
index.html - (intro page)
index.php - (actual webpage index file)
.htaccess rewrite rule
Sounds simple, but .htaccess redirects every webpage query back to my index.html file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
What is the best way to make it work?
Don't use mod_rewrite, use DirectoryIndex and give priority to index.html
DirectoryIndex index.html index.php
Note: While this should work, I don't recommend it as it creates ambiguity. One of those configuration changes that will haunt you later.
You can simply use DirectoryIndex directive for that:
DirectoryIndex index.html index.php
From the documentation:
The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the directory name. Local-url is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a file in the directory. Several URLs may be given, in which case the server will return the first one that it finds. If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory.

Categories