Optimize htaccess SEO WordPress | Millennials Consulting

Marketing and Business Intelligence

Optimize htaccess SEO WordPress

Julian Sanchez
Julian Sanchez
Know the best htaccess rules SEO Wordpress to work on your projects. Improve the SEO and fix bugs in htaccess.
wordpress htaccess seo

Carrying out a correct configuration of the Apache .htaccess file can help us speed up tasks, correct errors and even optimize part of the work SEO in our web positioning or maintenance projects. Today we tell you rules of ..htaccess SEO WordPress that you should know.

With the addition of rules in this file we can add an extra layer of security protection, such as preventing hotlinking, protecting WordPress (WP) directories and files, controlling bandwidth theft or compressing files.

It is very important to know how delicate this file is to handle since it controls the loading of the web page on the server. That is why we recommend make a backup or even download a copy of this file before editing it.

Basic list of Htaccess rules SEO WordPress

These simple rules will save you a lot of problems in web migrations or changes in web architecture.

1. Remove the "www" in all domain urls

#remove www from URI
Rewrit eEngine On
Rewrit eCond %{HTTP_HOST} ^www.dominio.com$ [NC]
Rewrit eRule ^(.*)$ http://dominio.com/$1 [L,R=301]

2. Remove file extension from a URL

Very useful to create beneficial friendly urls in SEO. Example: http://www.domain.com/crm.html – > http://www.domain.com/crm.

Rewrite Rule ^(([^/]+/)*[^.]+)$ /$1.php [L]

3. Remove a string from a URL

This rule is very useful to remove the well-known “category” from urls: http://domain.com/category/crm-> http://domain.com/crm. However, if we can configure it in WP, much better. When we start a project we must configure the structure of the permanlinks.

Rewrite Rule ^category/(.+)$ http://www.dominio.com/$1 [R=301,L]

4. Enable GZIP compression

This rule will help us to load the web faster.

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

5. 301 redirection from the old domain to a new one

Very useful rule to make a web migration or change of domain without losing traffic. In addition, with the use of rule 301 you will not incur a penalty SEO for duplicate content. If our domain was on another server we should only keep the file .htaccess is the old server for the redirect to take effect.

Rewrit eEngine On
Rewrit eRule ^(.*)$ http://www.nuevodominio.com/$1 [R=301,L]

6. Add trailing slash to the url

This is very useful to avoid duplicate content. For example, if our server serves urls like this www.domino.com/crm and www.domino.com/crm/ for Google are 2 different urls but we offer the same content.

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.)/$ RewriteRule (.) http://www.tudominio.com/$1/ [L,R=301]

7. 301 redirects by url and the rest to the home page

Through this rule we can redirect certain URLs to a new domain and the rest to the home page. In this case, the order of the rules is important, from top to bottom in order of preference.

# primero redirige las url objetivo y el resto a la home
Redirect /dierproefvrije-cosmetica-not-tested-on-animals/ https://dominio.com/nl/natuurlijke-cosmetica/
Redirect /bad-douche/ https://dominio.com/nl/producto/alo%C3%AB-vera-badgel-250ml/
Redirect /gezichtsverzorging/ https://dominio.com/nl/productcategorie/gelaats/
# el resto de urls a la home
redirectMatch 301 ^(.*)/$ https://dominio.com/nl/

8. Redirect domain and other urls

With this rule we can redirect all urls to the new domain.

redirectMatch 301 ^(.*)/$ https://nuevodominio.es/$1

9. Friendly 301 Redirects SEO

If you want to redirect a specific page without affecting the SEO you can use this rule.

Redirect 301 /d/file.html https://www.nuevodominio.com/r/file.html

10. Redirects to custom pages for each type of error

With this simple rule we can redirect each 40X error to a specific url.

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

11. Force cache expiration

This rule helps us load the page faster when the same user visits the web again.

FileETag MTime Size
ExpiresActive on
ExpiresDefault "access plus 86400 seconds"

DO WE CALL YOU?

Contact us to talk about your business. Our technicians and professionals will teach you the possibilities of improving your web positioning.

List of htaccess rules for security

With these rules you will be able to increase the security in your WordPress.

12. Add security headers

HTTP headers inform the web browser of how to act during its interaction with the website. These headers consist of metadata that provide information to the browser. Using the correct response headers we can strengthen security of the web.

For example, we can add strict transport security to force browsers to communicate with your website only over HTTPS.

Some headers are:

  • HTTP Strict Transport Security
  • X-Frame-Options
  • X-XSS-Protection
  • X-Content-Type-Options
  • Referrer-Policy
  • Feature-Policy
  • Content-Security-Policy
<IfModule mod_headers.c>
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-Content-Type-Options "nosniff"
    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    Header set Referrer-Policy "same-origin"
    Header set Feature-Policy "geolocation 'self'; vibrate 'none'"
    Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
    Header always set Expect-CT "max-age=7776000, enforce"
    Header always set Referrer-Policy: "no-referrer-when-downgrade"
    Header always set Permissions-Policy "geolocation=(); midi=();notifications=();push=();sync-xhr=();accelerometer=(); gyroscope=(); magnetometer=(); payment=(); camera=(); microphone=();usb=(); xr=();speaker=(self);vibrate=();fullscreen=(self);"  
    Header always set Content-Security-Policy "upgrade-insecure-requests"
    Header set X-Permitted-Cross-Domain-Policies &quot;none&quot;
</IfModule>

13. Disable directory browsing on your site

When the web server does not find an index file like index.php or index.html, it automatically displays a index page which shows the contents of the directory being vulnerable to hacker attacks.

index-of-htaccess-directories
Options -Indexes

14. File password protection

To increase the robustness of our fullfilment of security requirements in apache and wordpress we can include a password to access certain files and directories.

# proteger un archivo con contraseña
AuthType Basic
AuthName "Prompt"
AuthUserFile /home/path/.htpasswd
Require valid-user
# proteger un directorio con contraseña
resides
AuthType basic
AuthName "This directory is protected"
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user

15. Protect the htaccess file

With these rules you can protect access to any file, showing a 403 error page when someone tries to access:

# Protege el archivo htaccess
<files .htaccess>
order allow,deny
deny from all
</files>

# Protección extrema de htaccess
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>

16 Block web access by IP

If you observe too much spam in the comments or notes an increase in traffic of dubious reputation you have the option to block this access to the web knowing the IP.

allow from all
deny from 145.156.14.172
deny from 124.150.011

17. Redirect all traffic except certain IPs

Sometimes we may be interested in closing the web to all traffic except for certain IP's showing a 403 (accessing a folder to which we do not have permission).

ErrorDocument 403 http://www.midominio.com
Order deny,allow
Deny from all
Allow from 124.24.48.135
Allow from 102.14.68.143

18. Block access to bots

With the following rule we can block all user-agents that we do not want our website to be tracked, either because it is potentially harmful or to keep the load on the server low. We must first identify those bots and their user agents. For example, if we do not want the Ahrefs bot to track us, we will use the user-agent “User-agent: AhrefsBot”.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} ^AhrefsBot[NC]
    RewriteRule ^.* - [F,L]
</IfModule>

19. Prevent Hotlinking in htaccess

This rule helps us prevent other websites from using our images in their blogs hosted on our server thus reducing bandwidth consumption.

Options +FollowSymlinks
# Protect against hotlinking
Rewrit eEngine On
Rewrit eCond %{HTTP_REFERER} !^$
Rewrit eCond %{HTTP_REFERER} !^http://(www.)?nombrededominio.com/ [nc]
Rewrit eRule .*.(gif|jpg|png)$ http://nombrededominio.com/img/no_robar_ancho_de_banda.gif[nc]

DO WE CALL YOU?

Contact us to talk about your business. Our technicians and professionals will teach you the possibilities of improving your web positioning.

Conclusions

There are a large number of rules that can help us both in tasks SEO such as redirections or with friendly urls but also in web security. Although it is true that we cannot control 100% security, these simple rules will help us a lot in this regard.

Fonts

ullsdelmon.org

wordpress.org

Job Title
Htaccess SEO Wordpress
Article name
Htaccess SEO Wordpress
Description
Know the best htaccess rules SEO Wordpress to work on your projects SEO. Improve the SEO and fix bugs in htaccess.
Author
Posted by
Millennials Consulting
Logo

OUR CUSTOMERS THINK

English Today SL
English Today SL
3. July, 2023.
We are very happy with the result. It is true that since we made the agreement and signed, a few months of waiting have passed, but once the project started it has been very fast. It took a bit to focus on what was a priority for us, but after a few meetings everything went well. Good experience and we will continue working with them.
Sergio Jimenez Rodriguez
Sergio Jimenez Rodriguez
22. June, 2023.
Totally recommended
Myriam Sanchez
Myriam Sanchez
7. June, 2023.
Thank you very much for all the teaching and patience you had. The learning I had with you these months is incredible. Thank you so much!!!
no more barriers
no more barriers
1. June, 2023.
A very close service that makes them understand better what you want and need for your business. Special thanks to Alejandro Sánchez for the interest shown in the project.
Gonzalo Berrazueta
Gonzalo Berrazueta
1. June, 2023.
Very good service from the whole team. Special mention to José who is a crack.
Sara Monge
Sara Monge
3. May, 2023.
Working with Eliana has been a pleasure. He has been explaining everything to me very well and solving all the doubts about the project to be able to implement it in the company in the best possible way.
ALAYCA TRAVEL
ALAYCA TRAVEL
24. April, 2023.
As always a pleasure to work with Millennials Consulting, his team is full of professionals who help you at all times. You cannot be in better hands than theirs. I would repeat.
Hague Pilgrimages Travel
Hague Pilgrimages Travel
24. April, 2023.
It has been a pleasure working with them, they have helped us position our website in the top positions of Google and thereby increase our traffic and conversions on the web. We cannot be more delighted. A 10.
Central TCI
Central TCI
10. April, 2023.
Very happy with Diana and all her team

WHY TRUST IN MILLENNIALS CONSULTING?

Equipment_Millennials
0
COMPANIES have trusted us and digitized their business in MC
0
PROJECTS have been contracted by companies in the last 2 years.
0 %
of companies REPEAT working with Millennials Consulting in new projects.

SOME COMPANIES THAT TRUST US

LAST ENTRIES OF THE BLOG

OUR LOCATIONS

Madrid

Basilica Street, 15-17 1st Left. 28020

Novelda - Alicante

C. Mª Cristina 74, ground floor, 03660

Palma de Mallorca

Gran Via Asima 2 Floor 9 07009

Jalisco Mexico

C. Independence 329, 45100

E-MAIL OR TEXT US

DIGITALIZE YOUR COMPANY

CRM

We manage your business processes through software Zoho CRM for Business, which has an "all in 1" suite to manage your entire company, more than 40 tools interconnected with each other to better reach your business strategy.

SEO

It is not just being on the internet, your customers must find you through search engines. In Millennials Consulting We manage strategies positioning SEO so that your potential customers reach you first before your competition.

The website is the main letter of introduction of your business on the internet. "If you're not on the internet, you don't exist." A web design that communicates and reach your users will make the difference between your users and competitors by increasing your web traffic.

La digital strategies they are growing and we must be on the sidelines of this progress, that is why we connect tools that help to meet objectives.

We apply strategies Business Intelligence analyzing business data. We use the most sophisticated tools in the treatment and analysis of business data.

The connectivity of digital tools is one of our main pieces of digitization, using our alliances with digital partners .

KNOW OUR NETWORK OF PARTNERS

Our Team

jesus garcia team

J.Garcia

Manager

alexander trujillo team

A. Trujillo

Consultant, Implementer

HR Department

michael team

M. Anton

ERP specialist

ERP Dept.

irene bernardini

i. bernardini

ERP specialist

ERP Dept.

jessica team

J.Assaf

Consultant, Implementer Marketing Specialist

Marketing Department

D. Meledrez

Consultant, ADS Specialist Implementer

Marketing Department

eliana team

E. Perez

Consultant, Implanter Specialist in Design

Marketing Department

esther team

E. Martinez

Consultant, Implementer

Analytical Department

estiven team

E. Gallardo

Video Specialist

Marketing Department

dartboard team

D. Hernandez

Consultant, Implementer

Operations Department

jose team

J. Iñesta

Consultant, Implementer

Operations Department

gaspar photo team

G Gilabert

Business consultant

Commercial Department

Jesus-Alamo

J. Alamo

Consultant

Operations Department

marten team

M. Mateo

Consultant, Implementer

Operations Department

benjamin rosemary

B.Romero

Consultant, Developer

IT Department

julian team

J. Sanchez

Consultant SEO

Dept. SEO

alexander sanchez team

A. Sanchez

Consultant SEO

Dept. SEO

Alvaro Poveda Perez

TO. Poveda

Consultant SEO

Dept. SEO

Carlos

C. Hernandez

Consultant SEO

Dept. SEO

enrique

E. Monzó

Consultant SEO

Dept. SEO

frank team

F. More

Consultant, Developer 

IT Department

sheila team

S. Grocer

Commercial Consultant

Commercial Department

team valentine

V. Medina

Commercial Consultant

Commercial Department

Victor millennials consulting

v.cherry

consultant and implanter

anna team

A. Vallejo

Consultant, implanter

diego garber team

Mr. Thomas

Developer

jorge fernandez team

J. Fernández

Developer

jesus garber team

J. Garcia

Developer

team ignatius

I. Del Val

Developer

julian vicente team

J. Fenandez

Developer

Vincent Ares

V Ares

Legal and Grants Specialist

dawn mastic

A. Martinez

Grant Specialist

xavi agout

X. Agut

Web Consultant

ferdinand photo team

F. Lopez 

legal specialist

mariana photo team

Mr. Hernandez

PR

iago fernandez millennials consulting

I. Fernandez

ADS Specialist

irene riolobos

I. Riolobos

Consultant

Dept. Quality

jennifer cutillas

J. Cutillas

Consultant

Dept. Quality

photo natalia millennials consulting

N.Mesa

Consultant and implanter

Carolina millennials consulting

C. Naranjo

Commercial Consultant

Commercial Department

Ivan

I. Puche

consultant and implanter

Oscar millennials consulting

O. Munoz

consultant and implanter

Javi_MC (1)

J.Navarro

Developer

IT Department

louis zoho crm mexico

L. Macias

LATAM Consultant

Operations Department

HELLO! This form does not bite, you can write to us ;-)

ZHOLICS ICON (1)

Zoholics 2023

Códigos Discounts entries zoholics, Spain Chile and Mexico

Contact us and get your plan SEO