I'm trying to have the example.com
redirected to example.com/home.html
I have .htaccess
file in cPanel public HTML folder but it doesn't work
I'm new to this so apologies if it's completely wrong
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteRule ^[a-zA-Z0-9_/]{0,6}$ home.html [R=301,NC]
CodePudding user response:
you just add this code in the last line in .htaccess
RewriteRule ^/?$ "http\:\/\/example\.com\/home\.html" [R=301,L]
or
Redirect 301 http://example.com http://example.com/home.html
CodePudding user response:
It is bad practice to redirect the base URL. Instead you should just rename home.html
to index.html
. Then it will power http://example.com/
with no rules needed.
Another possibility is to use
DirectoryIndex home.html
in your .htaccess
which will change the name of the default page. Here is the documentation about what your default file should be named and how to change it if desired: mod_dir - DirectoryIndex Apache HTTP Server Version 2.4
You should also change links to your home page from <a href=home.html>
to <a href=/>
. Then users and search engines will never know the actual file name that powers your home page.