Last Updated: February 25, 2016
·
1.852K
· acrogenesis

.htaccess hacks

Specify the Directory Index:

DirectoryIndex newindex.html

Specify 404 error:

ErrorDocument 404 /404error.html

Redirect 301

Redirect 301 /old.html /new.html

Resolve www (make www.website.com become website.com)

RewriteEngine On RewriteCond %{HTTP_HOST} ^www.website.com [nocase] RewriteRule ^(.*) http://website.com/$1 [last,redirect=301

Deny access to specific ip (123.45.6.6)

order allow,deny deny from 123.45.6.6 allow from all

Prevent Hot linking

RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?website.com/.*$ [NC] RewriteRule \.(gif|jpg|css)$ - [F]

Make website.com/index.html redirect to website.com (SEO Remove duplicate index page)

RewriteEngine on # For index.html and index.htm only, without parameters, and only in the root: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/ RewriteRule ^index\.html?$ http://website.com/$1 [R=301,L]

Redirect a folder can be same site or a diferent site

RewriteRule ^sma/delicias(.*)$ http://canbeanothersite.com/delicias$1 [L,R=301]

2 Responses
Add your response

Can I make the redirection from index.html to website.com work with an index.php?

over 1 year ago ·

Use this

Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php HTTP/
RewriteRule ^index.php$ http://www.askapache.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
over 1 year ago ·