Apache – using .htaccess to serve index.html or index.php

.htaccessapachemod-rewrite

I want to use .htaccess file to return homepage (index.html) if direct access to the web site (no parameters), and index.php/subdirectories/…. if other links

example :

my_site.com displaying index.html

my_site.com/dir1/dir2/ must redirect to index.php with parameter dir1/dir2..

please help creating this .htaccess file

i have in existing file this :

RewriteEngine On

RewriteRule ^(.*)(.html|.htm)$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)/?$ index.php [L]

i want to do exception to index.html file which serve when entering site

thanks in advance

Best Answer

Try these rules in your .htaccess file:

RewriteEngine on
Options +FollowSymlinks -MultiViews

# to redirect my.site.com to my.site.com/index.html
RewriteRule ^$ /index.html [R,L]

# to redirect /dir1/dir2 to index.php?url=dir1/dir2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond  %{QUERY_STRING} !^url=
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?url=$1/$2 [R,L,QSA]
Related Topic