Reputation: 55
I am trying to redirect index.html to home.html and also remove that home.html from url via .htaccess. But it shows The page isn't redirecting properly. Which Means i need to redirect mydomain.com/index.html to mydomain.com/home.html and I need to show mydomain.com/ only when I visit index page.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 "/index.html" "/home.html"
RewriteCond %{THE_REQUEST} ^GET.*home\.html [NC]
RewriteRule (.*?)home\.html/*(.*) /$1$2 [R=301,NE,L]
</IfModule>
Upvotes: 2
Views: 966
Reputation: 804
// It's working code i hope it's useful ..
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 / http://newsite.com/
</IfModule>
or
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?http://dbdenterprise\.in$
RewriteRule ^(.*)$ http://dbdenterprise.com/$1 [R=301,QSA,L]
Upvotes: 0
Reputation: 11
What you could try instead of utilizing mod_rewrite is setting DirectoryIndex to the desired page (in your case home.html):
DirectoryIndex home.html
So, if you're calling domain.com/
it should give you the contents of domain.com/home.html
For reference, the Apache configuration manual: https://httpd.apache.org/docs/2.4/mod/mod_dir.html "DirectoryIndex Directive"
Referencing the conversation right below:
Maybe this could work (Sorry, I cant test it right now)
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} =/index.html
RewriteRule (.*?)home\.html/*(.*) /$1$2 [R=301,NE,L]
A bit of explanation: If the requested host matches example.com and the called URI is in fact not a real file or folder plus the URI equals to "index.html" it should redirect to home.html.
EDIT: As you dont want to show the home.html we can maybe get away by "proxying" the request internally instead of forcing an external redirect. Try to replace "R=301" in the last line (the RewriteRule) with "P" so it says RewriteRule (.*?)home\.html/*(.*) /$1$2 [P,NE,L]
Upvotes: 1