Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect root to index.php

I need to redirect from http://example.com/ to http://example.com/index.php.

like image 683
Davinel Avatar asked Apr 16 '12 14:04

Davinel


People also ask

How can I redirect and rewrite my urls with an .htaccess file?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

How do I redirect a root to a subfolder?

You can redirect all requests to a subdirectory by adding an . htaccess file to the root of your domain's directory: Visit the FTP page for instructions on how to upload. Once connected, upload (or create) a text file named .

What is RewriteEngine on htaccess?

htaccess rewrite rule includes setting a combination of rewrite condition ( RewriteCond ) tests along with a corresponding rule ( RewriteRule ) if the prior conditions pass. In most cases, these rules should be placed at any point after the RewriteEngine on line in the . htaccess file located in the website's docroot.


3 Answers

Use this:

DirectoryIndex index.php
like image 100
cfedermann Avatar answered Oct 13 '22 01:10

cfedermann


Just to add my own solution, since the answer of Michael did not work for me, I did something like:

RewriteEngine on

# These two lines redirect non-www to www.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) https://www.example.com$1 [R=301,L]

# These two lines redirect the root to index.html.
RewriteRule ^$ /index.html [R=301,L]
RewriteRule ^/$ /index.html [R=301,L]

This also preserves any possible existing query string parameters.

like image 43
Uwe Keim Avatar answered Oct 12 '22 23:10

Uwe Keim


Try this:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
like image 23
Michael Avatar answered Oct 12 '22 23:10

Michael