Reputation: 231
I have the following file system for my website which cannot be changed.
public_html
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.
Upvotes: 1
Views: 26
Reputation: 785196
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
.
Upvotes: 3
Reputation: 4124
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]
Upvotes: -1