Tag Archives: redirection

Some how-to using Htaccess

Some how to using Htaccess:

How to protected SVN Directories with HTACCESS File
This line in the “.htaccess” file will protect all SVN directories (“.svn/”):

<IfModule mod_rewrite.c>
RewriteRule ^(.*/)?\.svn/ - [F,L]
IfModule>

The flag “F” means forbidden, and the “L” flag means the last rule to be used if this rule is used. “-” is used to not change the original request URI. ErrorDocument can also be used with the rule to display a custom error message:

<IfModule mod_rewrite.c>
RewriteRule ^(.*/)?\.svn/ - [F,L]
ErrorDocument 403 "Access Denied"
</IfModule>

How to Force HTTPS
#force https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/ [L]

How to restrict no direct access of index.php
#no direct access of index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://%{HTTP_HOST}/ [R=301,L]

How to get all request come to Index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

How to hide file extension
RewriteCond %{REQUEST_URI} !^/(.*)(\.)
RewriteRule ^(.*)$ index.php?do=$1&%{QUERY_STRING} [NC,L]

Image 404 .htaccess
# img not found
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$
RewriteRule .* images/spacer.gif [L]

How to force all URL should be start with www.
#force www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www\.%{HTTP_HOST}/$1 [R=301,L]

How to Redirect 301 using htaccess
Redirect 301 /path/old.htm http://www.himanshoo.in/new.htm

How to hide config files to access for outside world
Example, don’t allow access to .ini files:
#no direct access of *.ini
RewriteRule ^(.*)\.ini$ http://%{HTTP_HOST}/ [R=301,L]

Category: Linux | Tags: ,