github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/htaccessFiles/.htaccess8 (about) 1 ########################### 2 # WP htaccess Boilerplate # 3 ########################### 4 5 ### https://github.com/Creare/WP-htaccess/ 6 7 ############ 8 # Security # 9 ############ 10 11 ### Recognise SSL when set at a load balancer/proxy level (CloudFlare) 12 SetEnvIf X-Forwarded-Proto https HTTPS=on 13 14 ### Prevent wp-config.php from being loaded: 15 <files wp-config.php> 16 order allow,deny 17 deny from all 18 </files> 19 20 ### Prevent sftp-config.json from being loaded: 21 <files sftp-config.json> 22 order allow,deny 23 deny from all 24 </files> 25 26 ### Protect .htaccess 27 <Files ~ "^.*\.([Hh][Tt][Aa])"> 28 order allow,deny 29 deny from all 30 satisfy all 31 </Files> 32 33 ### Secure wp-includes 34 <IfModule mod_rewrite.c> 35 RewriteEngine On 36 RewriteBase / 37 RewriteRule ^wp-admin/includes/ - [F,L] 38 RewriteRule !^wp-includes/ - [S=3] 39 RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] 40 RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L] 41 RewriteRule ^wp-includes/theme-compat/ - [F,L] 42 </IfModule> 43 44 ### Prevent directory browsing 45 <IfModule mod_autoindex.c> 46 Options -Indexes 47 </IfModule> 48 49 ### Prevent this .htaccess from being accessed: 50 <files .htaccess> 51 order allow,deny 52 deny from all 53 </files> 54 55 ### Prevent WordPress' readme.html from being accessed (it contains the version number) 56 <files readme.html> 57 Deny from all 58 </files> 59 60 ### Disable HTTP Trace 61 RewriteEngine On 62 RewriteCond %{REQUEST_METHOD} ^TRACE 63 RewriteRule .* - [F] 64 65 ### Block access to hidden files & directories 66 <IfModule mod_rewrite.c> 67 RewriteCond %{SCRIPT_FILENAME} -d [OR] 68 RewriteCond %{SCRIPT_FILENAME} -f 69 RewriteRule "(^|/)\." - [F] 70 </IfModule> 71 72 ### Block access to source files 73 <FilesMatch "(^#.*#|\.(bak|config|dist|fla|inc|ini|log|psd|sh|sql|sw[op])|~)$"> 74 Order allow,deny 75 Deny from all 76 Satisfy All 77 </FilesMatch> 78 79 80 ############################### 81 # Additional Rewrite Settings # 82 ############################### 83 84 # Option 1 85 # http://domain > http://www.domain 86 87 <IfModule mod_rewrite.c> 88 # Options +FollowSymlinks #Not supported by some hosting 89 ### If you wish to redirect to a https:// simply substitute http: with https: 90 RewriteCond %{HTTP_HOST} !^www\..+$ [NC] 91 RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 92 ### Redirect away from /index.php to clear path 93 RewriteCond %{THE_REQUEST} ^.*/index.php 94 RewriteRule ^(.*)index.php$ http://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L] 95 </IfModule> 96 97 # Option 2 98 # http://www.domain > http://domain 99 100 #<IfModule mod_rewrite.c> 101 # Options +FollowSymlinks #Not supported by some hosting 102 ### If you wish to redirect to a https:// simply substitute http: with https: 103 #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 104 #RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] 105 ### Redirect away from /index.php to clear path 106 #RewriteCond %{THE_REQUEST} ^.*/index.php 107 #RewriteRule ^(.*)index.php$ http://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L] 108 #</IfModule> 109 110 111 ############################## 112 # Default Wordpress Settings # 113 ############################## 114 115 # BEGIN WordPress 116 <IfModule mod_rewrite.c> 117 RewriteEngine On 118 RewriteBase / 119 ### SQL Injection Protection 120 RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR] 121 RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 122 RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 123 RewriteRule ^(.*)$ index.php [F,L] 124 ### End SQL Injection Protection 125 RewriteRule ^index\.php$ - [L] 126 RewriteCond %{REQUEST_FILENAME} !-f 127 RewriteCond %{REQUEST_FILENAME} !-d 128 RewriteRule . /index.php [L] 129 </IfModule> 130 131 # END WordPress 132 133 ####################### 134 # Speed & Compression # 135 ####################### 136 137 # BEGIN Expire headers 138 <ifModule mod_expires.c> 139 ExpiresActive On 140 ExpiresDefault "access plus 5 seconds" 141 ExpiresByType image/x-icon "access plus 2592000 seconds" 142 ExpiresByType image/jpeg "access plus 2592000 seconds" 143 ExpiresByType image/png "access plus 2592000 seconds" 144 ExpiresByType image/gif "access plus 2592000 seconds" 145 ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 146 ExpiresByType text/css "access plus 604800 seconds" 147 ExpiresByType text/javascript "access plus 216000 seconds" 148 ExpiresByType application/javascript "access plus 216000 seconds" 149 ExpiresByType application/x-javascript "access plus 216000 seconds" 150 ExpiresByType text/html "access plus 600 seconds" 151 ExpiresByType application/xhtml+xml "access plus 600 seconds" 152 </ifModule> 153 # END Expire headers 154 155 156 <ifModule mod_headers.c> 157 # BEGIN Cache-Control Headers 158 <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> 159 Header set Cache-Control "public" 160 </filesMatch> 161 <filesMatch "\.(css)$"> 162 Header set Cache-Control "public" 163 </filesMatch> 164 <filesMatch "\.(js)$"> 165 Header set Cache-Control "private" 166 </filesMatch> 167 <filesMatch "\.(x?html?|php)$"> 168 Header set Cache-Control "private, must-revalidate" 169 </filesMatch> 170 # END Cache-Control Headers 171 </ifModule> 172 173 174 <IfModule mod_deflate.c> 175 AddOutputFilterByType DEFLATE text/xhtml text/html text/plain text/xml text/javascript application/x-javascript text/css 176 BrowserMatch ^Mozilla/4 gzip-only-text/html 177 BrowserMatch ^Mozilla/4\.0[678] no-gzip 178 BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 179 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary 180 Header append Vary User-Agent env=!dont-vary 181 </IfModule> 182 183 AddOutputFilterByType DEFLATE text/html 184 AddOutputFilterByType DEFLATE text/plain 185 AddOutputFilterByType DEFLATE text/xml 186 AddOutputFilterByType DEFLATE text/css 187 AddOutputFilterByType DEFLATE text/javascript 188 AddOutputFilterByType DEFLATE application/x-javascript 189 190 #Remove the ETag header 191 Header unset ETag 192 FileETag None 193 194 195 ####################### 196 # File Format Support # 197 ####################### 198 199 ### Add support for SVG and HTC 200 AddType image/svg+xml svg svgz 201 AddEncoding gzip svgz 202 AddType text/x-component .htc 203 204 205 ######################## 206 # Manual 301 Redirects # 207 ######################## 208 209 #redirect 301 /old-page-url.html https://www.domain.co.uk/new-page-url