April 25, 2019

.htaccess snippets

Simple cut-and-paste snippets for your .htaccess files when working with static and WordPress websites.

Deny access to wp-config.php

<files wp-config.php>
order allow,deny
deny from all
</files>

301 Redirect

Redirect 301 /oldpage.htm https://www.your-website.com/newpage.htm

Force www domain

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^your-website.com [NC]
RewriteRule ^(.*)$ https://www.your-website.com/$1 [L,R=301,NC]