Wordpress .HTACCESS File Generic Code

4 replies
  • WEB DESIGN
  • |
I am new to wordpress and i am learning about the .HTACCESS file and what code/script should be in the that file - like the bare minimum- for a brand new website.

Here is what I have so far:

Code:
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
        AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml
    </IfModule>
</IfModule>

# END W3TC Browser Cache

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN Disable Directory Browsing
Options All -Indexes

# END Disable Directory Browsing

# BEGIN Prevent access to WP-Config
<Files wp-config.php>
order allow,deny
deny from all
</Files>

# END Prevent access to WP-Config

# BEGIN Protect HTACCESS file
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>

# END Protect HTACCESS file

# BEGIN Canonical Domain Rewrite
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]

# END Canonical Domain Rewrite

# BEGIN Prevent Directory Browsing
directory browsing
Options All -Indexes

# END Prevent Directory Browsing

# BEGIN Prevent Hotlinking of images
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://domain.com/hot-link.gif [L]

# END Prevent Hotlinking of images

# BEGIN Custom 404 page
ErrorDocument 404 /notfound.html

# END Custome 404 page
Is this good enough? Is the code structured correctly? Is there anything else that should be included for a generic, brand new website?
#code #file #generic #htaccess #wordpress

Trending Topics