Wordpress Htaccess | Adrenalina

WordPress Htaccess

Publicado Por | 19 abril , 2013 | Blog Adrenalina En, Technical SEO | No Comments

Configure WordPress administration

After an overview on the Rich snippets, I’ve prepared some guidelines to correctly configure the URLs in our wordpress. We must try to make sure they occupy the minimum number of characters so everytime we do a new installation we must avoid the “www” initials and the final “/” in the URL constructions. To achieve that we’ll do the following modifications in the admin panel.

In SettingsPermanent Links we’d use the customized structure


When we skip the final “/” we shorten the URL by one value.

In Main Adjustments WordPress Address (URL) & Site Address (URL) we must insert this line:


Before, the “www” had a logic to them because they identified the protocol of how the server was accessed but nowadays it’s better to skip them to shorten the URL.

Once we do the aforementioned edits then we must insert the following line in our wordpress’ htaccess.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Website or WordPress Htaccess

We’ll now detail some edits to carry out in the .htaccess file of a wordpress to improve various aspects of the site and, in several cases, useful for most sites. Given how .htaccess is a very critical file for the functioning of wordpress we suggest creating a backup before doing any changes.

Htacces gzip compression

ExpiresActive On
ExpiresDefault A0
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript image/svg+xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Activate the WordPress cache

<FilesMatch "\.(css|js|gif|jpeg|png|ico)$">
ExpiresActive On
ExpiresDefault "access plus 1 year"

Tell it you don’t want the ETag tagging

FileETag none

Custom error pages

ErrorDocument 403 /access_forbidden.php
ErrorDocument 404 /page_not_found.php
ErrorDocument 500 /error_page.php

301 Redirecting in htaccess

In this Google support center video some interesting reccomendations are brought up.

You can do them in 3 different manners in Apache as told below:


Used for redirection of a few static URLs

Redirect 301 /pagina_vieja.php http://tudominio.com/pagina_nueva.php


Uses regular expressions which allows one to us patterns

redirectMatch 301 (.*)\.html$ http://tudominio.com$1.php
redirectMatch 301 ^/pagina_vieja.php http://tudominio.com/pagina_nueva.php
redirectMatch 301 ^/carpeta_vieja/ http://tudominio.com


Use of flag R and very similar to redirectMatch but allows for changes using RewriteCond

De www.tudominio.com a tudominio.com

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.tudominio.com\.com
RewriteRule (.*) tudominio.com/$1 [R=301,L]

De tudominio.com a www.tudominio.com

RewriteEngine on
RewriteCond %{HTTP_HOST} ^midominio.com [NC]
RewriteRule ^(.*)$ http://www.midominio.com/$1 [L,R=301]

Not allowing image theft (hotlinking) showing a customized image

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?tusitioweb\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?otrositioweb\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.google.com/reader/view/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.google.com/reader/m/view/.*$ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ nuevaimagen.gif [L]

Protect pages and posts’ comments from spam

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Protect against sql injections

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

Restricts access to wordpress wp-admin

<Files wp-login.php>
Order Deny, Allow
Deny from all
Allow from xxx.xxx.xxx.xxx
Allow from xxx.xxx.xxx.xxx

Block IPs or bots

order allow,deny
allow from all
deny from xxx.xxx.xxx.xxx

Once any of the suggested edits have been carried out you should check that the whole site works neatly enough and if something goes wrong restore the copy of .htaccess of its wordpress.
We must remember something very important: to make sure the htaccess permits remain at 644 and, above all, remember that the edits in this file are the most critical actions which you can do within a site.

BE VERY CAREFUL when altering the .htaccessof your wordpress o website. If you need some help, we’re a SEO agency specialized in WordPress. Don’t doubht it: we’re the best partnet when it comes to responsive web apps development.

Autor: mauro flores

Estudiamos y analizamos su negocio en profundidad, definimos objetivos y planteamos la estrategia de marketing más adecuada centrándonos en conseguir cada uno de los objetivos propuestos. Solicita Presupuesto Ahora

Uso de cookies

En este sitio web utilizamos cookies propias y de terceros para mejorar nuestros servicios, para que usted tenga la mejor experiencia de usuario y analizar su visita. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.