1

I have the following file system for my website which cannot be changed.

public_html

  • css
  • js
  • .(other such folders)
  • .
  • vtu (<-The one I need to redirect to)

I need to ensure that all folders except 'vtu' cannot be accessed (and preferably should redirect to 'vtu'). And also, the home page

example.com should redirect to

example.com/vtu

Putting it in simple terms, if anything other than the vtu sub directory or its content(s) is requested for, there should be a redirect to example.com/vtu

I hope my problem has been expressed clearly enough.

adarshdec23
  • 231
  • 2
  • 9
  • take a look at this http://stackoverflow.com/questions/5411538/how-to-redirect-from-an-html-page – valbu17 Jul 19 '14 at 18:15

2 Answers2

3

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^vlu(/.*)?$ /vlu [L,NC]

First 2 conditions avoid rewriting for real files and real directories. RewriteRule has condition !^vlu(/.*)$ which basically means don't rewrite if request is already for vlu or any of its sub directories. In the action part it just forwards to /vlu.

anubhava
  • 761,203
  • 64
  • 569
  • 643
-1

Just put this in your index.html in the head section..

<meta http-equiv="refresh" content="0; url=http://example.com/" />

or to not access your folders within your .htaccess

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$       [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$          [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$   [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC]
RewriteRule .*\.(.*)$ http://www.example.com               [R,NC]
valbu17
  • 4,034
  • 3
  • 30
  • 41
  • That would only redirect the user from the home page. What if, the user enters example.com/heShouldNotSeeThis ? – adarshdec23 Jul 19 '14 at 18:20