Skip to content

Instantly share code, notes, and snippets.

@pixelpylon
Last active August 28, 2019 02:44
Show Gist options
  • Save pixelpylon/8af955f2958b3b1e03d444068a817f7f to your computer and use it in GitHub Desktop.
Save pixelpylon/8af955f2958b3b1e03d444068a817f7f to your computer and use it in GitHub Desktop.
sample .htaccess file for wp project with redirect to www and https
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
<Files xmlrpc.php>
order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files wp-config.php>
order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files wp-login.php>
order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files info.php>
order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
Redirect 301 /old-page /new-page
#ModPagespeed off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment