WordPress: My Additional Parts To .htaccess In Production
Tags: wordpress, apache, htaccess
Published: 2018-12-10 10:15:55

---
title: WordPress: My Additional Parts To .htaccess In Production
published: true
description: I have 3 sections in .htaccess of WordPress websites to be added when I publish them. One is for security and the others are for performance.
tags: wordpress, apache, htaccess
---

# Introduction

I have 3 sections in .htaccess of WordPress websites to be added when I publish them.
One is for security and the others are for performance.

# My Additional Parts

### Section \#1: Denial Of .git Access

It's for security.
I never want .git logs exposed even by accident although I don't have a habit to use Git in production environment.

```apache
RedirectMatch 404 /\.git
```

### Section \#2: Compression Of Data Transfer

It's for performance.
(I like checking my websites with Google's [web.dev](https://web.dev/measure) / [PageSpeed Insights](https://developers.google.com/speed/pagespeed/insights/).)


```apache
<IfModule mod_deflate.c>
# compress html/css/javascript/text/xml/font
AddOutputFilterByType DEFLATE application/javascript
...
</IfModule>
```

### Section \#3: Browser Caching

It's also for performance.

```apache
<IfModule mod_deflate.c>
ExpiresActive On
ExpiresByType image/gif "access plus 3 weeks"
...
</IfModule>
```

# Conclusion

To sum up, my .htaccess in production is like this:

```apache
# BEGIN WordPress
...

# END WordPress

RedirectMatch 404 /\.git

<IfModule mod_deflate.c>
# compress html/css/javascript/text/xml/font
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# escape from bugs of pretty old browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>

<IfModule mod_deflate.c>
ExpiresActive On
ExpiresByType image/gif "access plus 3 weeks"
ExpiresByType image/jpeg "access plus 3 weeks"
ExpiresByType image/png "access plus 3 weeks"
ExpiresByType image/x-icon "access plus 2 weeks"
ExpiresByType text/css "access plus 1 weeks"
ExpiresByType text/javascript "access plus 1 weeks"
ExpiresByType application/javascript "access plus 1 weeks"
ExpiresByType application/x-javascript "access plus 1 weeks"
</IfModule>
```

I'm happy if you would tell me about how to correct or advance them 😄

Happy serving 🕊