redirect index.html to display as home

stricken

Expert Member
Joined
Sep 5, 2010
Messages
2,265
what webserver are you using? If Apache, you need to include an .htaccess file with ModRewrite rules, although other webservers work similarly. Google "URL Rewrite"
 

Jade @ Absolute Hosting

Absolute Hosting Representative
Company Rep
Joined
Nov 17, 2015
Messages
1,086
As stricken suggested, you'll need to implement a url rewrite for that.

If you advise as to what server you're hosting your site on I'm sure some one here will be able to provide you with a working example.
 

John8

Active Member
Joined
Jan 11, 2015
Messages
39
As stricken suggested, you'll need to implement a url rewrite for that.

If you advise as to what server you're hosting your site on I'm sure some one here will be able to provide you with a working example.


Hi guys

Thanks for your prompt responses. I hope this will help you, but it is hosted with Axxess.
 

John8

Active Member
Joined
Jan 11, 2015
Messages
39
As stricken suggested, you'll need to implement a url rewrite for that.

If you advise as to what server you're hosting your site on I'm sure some one here will be able to provide you with a working example.

Hi guys

Thanks for your prompt responses. I hope this will help you, but it is hosted with Axxess.
 

Jade @ Absolute Hosting

Absolute Hosting Representative
Company Rep
Joined
Nov 17, 2015
Messages
1,086
Hi Pottie8

Do you know if the site is hosted on their shared linux servers, windows servers or on a vps?
 

_neo

Well-Known Member
Joined
May 20, 2015
Messages
418
Please try the following:

1. Create a file named .htaccess in the same directory as your index.html file. You can create this with the cPanel file manager, or by using FTP.

2. Enter the following into that file:

Options -Multiviews

RewriteEngine On

RewriteCond ^Home/?$ /index.html [L]
RewriteCond ^Information/?$ /info.html [L]


The /? bit means that the trailing slash is optional, so /Home/ and /Home will both work

I don't recommend using Home, however, as Google and other search engines will see that as a duplicate of the site root, which negatively affects rankings. If this is just a small project you're learning with, however, then there is no issue - but always keep it in mind.

Speaking of duplicate content, I also recommend trimming out the trailing slash if it is present. If you want to do that, use this in your file instead:

Options -Multiviews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=302,L]

RewriteCond ^Home$ /index.html [L]
RewriteCond ^Information$ /info.html [L]


If you're happy with how that all works, then change 302 to 301 to make the redirect cached.

Also make sure that Home and Information do not exist as directories.

:)
 

John8

Active Member
Joined
Jan 11, 2015
Messages
39
Please try the following:

1. Create a file named .htaccess in the same directory as your index.html file. You can create this with the cPanel file manager, or by using FTP.

2. Enter the following into that file:

Options -Multiviews

RewriteEngine On

RewriteCond ^Home/?$ /index.html [L]
RewriteCond ^Information/?$ /info.html [L]


The /? bit means that the trailing slash is optional, so /Home/ and /Home will both work

I don't recommend using Home, however, as Google and other search engines will see that as a duplicate of the site root, which negatively affects rankings. If this is just a small project you're learning with, however, then there is no issue - but always keep it in mind.

Speaking of duplicate content, I also recommend trimming out the trailing slash if it is present. If you want to do that, use this in your file instead:

Options -Multiviews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=302,L]

RewriteCond ^Home$ /index.html [L]
RewriteCond ^Information$ /info.html [L]


If you're happy with how that all works, then change 302 to 301 to make the redirect cached.

Also make sure that Home and Information do not exist as directories.

:)

@_neo saves the day* Thank you ever so much for the thorough information! I will test that out as soon as I have a moment and revert back to you. Thank you once again! :) :) :)
 

John8

Active Member
Joined
Jan 11, 2015
Messages
39
No luck

Please try the following:

1. Create a file named .htaccess in the same directory as your index.html file. You can create this with the cPanel file manager, or by using FTP.

2. Enter the following into that file:

Options -Multiviews

RewriteEngine On

RewriteCond ^Home/?$ /index.html [L]
RewriteCond ^Information/?$ /info.html [L]


The /? bit means that the trailing slash is optional, so /Home/ and /Home will both work

I don't recommend using Home, however, as Google and other search engines will see that as a duplicate of the site root, which negatively affects rankings. If this is just a small project you're learning with, however, then there is no issue - but always keep it in mind.

Speaking of duplicate content, I also recommend trimming out the trailing slash if it is present. If you want to do that, use this in your file instead:

Options -Multiviews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=302,L]

RewriteCond ^Home$ /index.html [L]
RewriteCond ^Information$ /info.html [L]


If you're happy with how that all works, then change 302 to 301 to make the redirect cached.

Also make sure that Home and Information do not exist as directories.

:)



Hi _neo

Still no luck. My current htaccess file displays as follow:

RewriteOptions inherit

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mydomain\.co\.za$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.co\.za$
RewriteRule ^home$ "http\:\/\/www\.mydomain\.co\.za\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^mydomain.co.za$
RewriteRule ^/?$ "http\:\/\/www\.mydomain\.co\.za\/" [R=301,L]


Ive adding your info, ive tried removing all mine and just leaving yours, could you by any chance advise further?

Pottie8*
 

_neo

Well-Known Member
Joined
May 20, 2015
Messages
418
Hi _neo

Still no luck. ... Ive adding your info, ive tried removing all mine and just leaving yours, could you by any chance advise further?

Pottie8*

Please give the following a try - notes are in the code comments.
Whenever you want to add a new rewrite, just duplicate the last line and change the data accordingly.

# Disable Multiviews
Options -MultiViews

# Set the directory index
DirectoryIndex index.html

# Turn on RewriteEngine and inherit options
RewriteEngine on
RewriteOptions inherit

# Remove www. and strip out trailing slash
RewriteCond %{HTTP_HOST} ^www\.mydomain\.co\.za [NC]
RewriteRule ^(.*)/?$ http://mydomain.co.za/$1 [R=301,END]

# Strip out trailing slash if it hasn't been
# stripped out already
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=302,END]

# REDIRECT /Home to domain root
# Domain root will display index.htnl due to DirectoryIndex directive above
RewriteRule ^home$ / [NC,R=302,END]

# INTERNALLY REWRITE /Information to /info.html
RewriteRule ^information$ /info.html [NC,L]
 

Hamster

Resident Rodent
Joined
Aug 22, 2006
Messages
37,829
You can't just drop the index.html file in a /Home and /Information directory?
 

John8

Active Member
Joined
Jan 11, 2015
Messages
39
Please give the following a try - notes are in the code comments.
Whenever you want to add a new rewrite, just duplicate the last line and change the data accordingly.

# Disable Multiviews
Options -MultiViews

# Set the directory index
DirectoryIndex index.html

# Turn on RewriteEngine and inherit options
RewriteEngine on
RewriteOptions inherit

# Remove www. and strip out trailing slash
RewriteCond %{HTTP_HOST} ^www\.mydomain\.co\.za [NC]
RewriteRule ^(.*)/?$ http://mydomain.co.za/$1 [R=301,END]

# Strip out trailing slash if it hasn't been
# stripped out already
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=302,END]

# REDIRECT /Home to domain root
# Domain root will display index.htnl due to DirectoryIndex directive above
RewriteRule ^home$ / [NC,R=302,END]

# INTERNALLY REWRITE /Information to /info.html
RewriteRule ^information$ /info.html [NC,L]



Hi _Neo

I get error 500 when I change to the code provided.

:)
 
Top