skip to Main Content

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]

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search