Gissipi_453
Gissipi_453

Reputation: 1340

How can I make a website such that when a user enters any URL related to the website, it opens up the index page

Let us suppose I have a static HTML website 'example.com/index.html' and I have another page that has URL 'example.com/contact-us.html'.

Someone enters the URL 'example.com/contact-us.html' in the browser when he wants to go to contact-us.html page directly. But I want the index page opened in this case. But once the website is loaded on the browser with the index page, the user must be able to navigate through links on the website as per his wish.

Is this possible ? If yes, how ?

Upvotes: 0

Views: 139

Answers (1)

Sébastien
Sébastien

Reputation: 2394

If you want to prevent users to open pages directly except for the index, you can check the referer, and redirect to the index page if the referer doesn't match your website.

Are you using Apache? If you are, you can use mod_rewrite to do this.

First, enable mod_rewrite, usually by uncommenting the following line in the httpd.conf file:

LoadModule rewrite_module modules/mod_rewrite.so

Then create a .htaccess file in the same folder as index.html with the following content:

RewriteEngine on

RewriteRule ^index.html$ index.html [QSA,L]

RewriteCond %{HTTP_REFERER} !^http://example\.com/.*$
RewriteRule ^.*$ /index.html [R,L]

Upvotes: 3

Related Questions