Forum Moderators: phranque
# disable directory browsing
Options All -Indexes
# BEGIN WordPress
RewriteEngine on
#
# Unless you have set a different RewriteBase preceding this
# point, you may delete or comment-out the following
# RewriteBase directive:
RewriteBase /
#
# if this request is for "/" or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
#
# END Wordpress
# Add Proper MIME-Type for Favicon / gzip
AddType image/x-icon .ico
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
# BEGIN Compress text files
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \\.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
# END Compress text files
# BEGIN Expire headers
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 604800 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 1209600 seconds"
ExpiresByType text/javascript "access plus 1209600 seconds"
ExpiresByType application/x-javascript "access plus 1209600 seconds"
ExpiresByType application/javascript "access plus 1209600 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType application/xhtml+xml "access plus 604800 seconds"
</IfModule>
# END Expire headers
# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\\\.(css)$">
Header set Cache-Control "max-age=1209600, public"
</FilesMatch>
<FilesMatch "\\\\.(js)$">
Header set Cache-Control "max-age=1209600, private"
</FilesMatch>
<FilesMatch "\\\\.(x?html?|php)$">
Header set Cache-Control "max-age=604800, no-cache, must-revalidate"
</FilesMatch>
</IfModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
<IfModule mod_headers.c>
# properly handle requests coming from behind proxies
Header append Vary User-Agent
# remove ETags, it's important
Header unset ETag
FileETag None
Header unset Last-Modified
</IfModule>
# END Turn ETags Off
Options All -Indexes
Mixing Options with a + or - with those without is not valid syntax, and is likely to cause unexpected results.
<FilesMatch "\\\\.(js)$">
Options All -Indexes <FilesMatch "\\\\.(js)$"> Should I change the four backslashes to just three for this line of code only, or for every instance?
# if this request is for "/" or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L] # if this request is for "/" or has already been rewritten to WP
# or if request is for image, css, or js file
# or if URL resolves to existing file
# or if URL resolves to existing directory
# then skip the rewrite to WP
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L] This code is courtesy of jdmorgan, who posted it here
[S=1]
RewriteCond $1 ^(index\.php)?$
RewriteCond $1 \.(gif|jpg|css|js|ico)$
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . /index.php [L]
# disable directory browsing
Options -Indexes
# BEGIN WordPress
RewriteEngine on
RewriteBase /
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
# END Wordpress
# Add Proper MIME-Type for Favicon / gzip
AddType image/x-icon .ico
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
# BEGIN Compress text files
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \\.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
# END Compress text files
# BEGIN Expire headers
ExpiresActive On
ExpiresDefault "access plus 604800 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 1209600 seconds"
ExpiresByType text/javascript "access plus 1209600 seconds"
ExpiresByType application/x-javascript "access plus 1209600 seconds"
ExpiresByType application/javascript "access plus 1209600 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType application/xhtml+xml "access plus 604800 seconds"
# END Expire headers
# BEGIN Cache-Control Headers
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\\\.(css)$">
Header set Cache-Control "max-age=1209600, public"
</FilesMatch>
<FilesMatch "\.js">
Header set Cache-Control "max-age=1209600, private"
</FilesMatch>
<FilesMatch "\\\\.(x?html?|php)$">
Header set Cache-Control "max-age=604800, no-cache, must-revalidate"
</FilesMatch>
# END Cache-Control Headers
# BEGIN Turn ETags Off
Header append Vary User-Agent
Header unset ETag
FileETag None
Header unset Last-Modified
# END Turn ETags Off
RewriteRule . /index.php [L] Wrong. It should say .* because if the user requests the sitename by itself, then the request will have no content.
example.com/ will be handled by the DirectoryIndex index.php directive. RewriteCond $1 ^(index\.php)?$ code is also correct. # disable directory browsing
Options -Indexes
# BEGIN WordPress
RewriteEngine on
RewriteBase /
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
# END Wordpress
# Add Proper MIME-Type for Favicon / gzip
AddType image/x-icon .ico
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
# BEGIN Compress text files
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \\.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
# END Compress text files
# BEGIN Expire headers
ExpiresActive On
ExpiresDefault "access plus 604800 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 1209600 seconds"
ExpiresByType text/javascript "access plus 1209600 seconds"
ExpiresByType application/x-javascript "access plus 1209600 seconds"
ExpiresByType application/javascript "access plus 1209600 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType application/xhtml+xml "access plus 604800 seconds"
# END Expire headers
# BEGIN Cache-Control Headers
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\\\.(css)$">
Header set Cache-Control "max-age=1209600, public"
</FilesMatch>
<FilesMatch "\.js">
Header set Cache-Control "max-age=1209600, private"
</FilesMatch>
<FilesMatch "\\\\.(x?html?|php)$">
Header set Cache-Control "max-age=604800, no-cache, must-revalidate"
</FilesMatch>
# END Cache-Control Headers
# BEGIN Turn ETags Off
Header append Vary User-Agent
Header unset ETag
FileETag None
Header unset Last-Modified
# END Turn ETags Off
<FilesMatch "\\\\.(x?html?|php)$"> should be <FilesMatch "\.(x?html?|php)$"> ExpiresByType text/html "access plus 1 seconds"
<FilesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=604800, no-cache, must-revalidate"
</FilesMatch> ExpiresByType text/html "access plus 1 seconds"
<FilesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=604800, no-cache, must-revalidate"
</FilesMatch> I am wondering if I should change all the multiple backslashes \\\\ to a single?
If you look at this thread here, it seems like jdmorgan knows his stuff