SlideShare a Scribd company logo
@RoxanaStingu
> .htaccess for SEOs
Roxana Stingu // Alamy
SLIDESHARE.NET/RoxanaStingu
@RoxanaStingu
@RoxanaStingu
> About me
The world’s
most
diverse stock
photo
collection
@RoxanaStingu
Image License
in Google
Images
roxana-
stingu.com/licensable-tags
@RoxanaStingu
Page
162
@RoxanaStingu
> How does it help with SEO?
REDIRECTS
PAGE SPEED
CRAWLING and INDEXING
@RoxanaStingu
.htaccess is very powerful –
even a missing space can result
in server malfunction.
DON’T make .htaccess changes
without a proper back-up!
> Disclaimer
@RoxanaStingu
WHAT IS THE .HTACCESS FILE?
@RoxanaStingu
Level 1 Level 2
@RoxanaStingu
httpd.conf .htaccess
@RoxanaStingu
> httpd.config
LOADS ONLY ONCE
@RoxanaStingu
@RoxanaStingu
/level1/level2/level3/index.html
Root
.htaccess
Level 1
.htaccess
Level 2
.htaccess
Level3
REQUEST
WEBSITE
STRUCTURE
@RoxanaStingu
> Why still use .htaccess?
SHARED HOSTING
DEVELOPERS
@RoxanaStingu
> Recommendations
AVOID IT IF YOU CAN
GET FRIENDLY WITH IT IF YOU CAN’T
@RoxanaStingu
THE BASICS
@RoxanaStingu
> .htaccess speed dating
FULL NAME Hyper Text Access
JOB Affects the folder it’s placed in
ORIENTATION Execution order is top to bottom (mostly)
LANGUAGES Directives
@RoxanaStingu
> Regular expressions
@RoxanaStingu
@RoxanaStingu
REDIRECTS
@RoxanaStingu
> Main redirect modules
mod_alias
mod_rewrite
@RoxanaStingu
> mod_alias
# Redirect [status] [URL-path] URL
### Example
Redirect 301 "/old-url.html" "/new-url.html“
# RedirectMatch [status] regex URL
### Example
RedirectMatch 301 "(.*).pdf$" "$1.html"
.htaccess
@RoxanaStingu
> mod_rewrite
### Example
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteEngine off
.htaccess
@RoxanaStingu
> RewriteRule syntax
RewriteRule Pattern Substitution [FLAGS]
Reg. expr. checked
against the
requested URI
Any of the following:
- modification to the part matched by the Pattern
- absolute path to a file
- full URL to redirect to
- a dash “-” to do nothing
Optional - All kinds
of special actions
@RoxanaStingu
> Rewrite flags
G | Gone
N | Next
NC | NoCase
QSA | QSAppend
QSD | QSDiscard
R | Redirect
@RoxanaStingu
> Back-references
REQUEST
/test/1234
RESPONSE
/admin.foo?page=test&id=1234&host=admin.example.com
@RoxanaStingu
> Redirect chains
@RoxanaStingu
> Redirect chains
0
0.5
1
1.5
2
2.5
1 2 3 4 5 6 7 8
TimeinS
# of redirects before the final destination
Redirect Chains Compared to Speed
Series2 Series3 Series4
@RoxanaStingu
Indexing Google stops after [3 to 5] redirects
Crawling Wastes crawl budget
Speed Each step slows down the time it takes
for a page to load
@RoxanaStingu
Update redirect destinations
/old-url.html should 301 to /new-url.html
https://www.website.com/old-url.html HTTP STATUS 301
/some-other-page.html
301
@RoxanaStingu
> Fixing redirect chains
PROBLEM A 301 B 301 C
IMPLEMENTATION A 301 to B
IMPLEMENTATION B 301 C
FIX Change A 301 to B with A 301 C
@RoxanaStingu
> Duplicate content
1. http://example.com/blog
2. http://example.com/blog/
3. http://www.example.com/blog
4. http://www.example.com/blog/
https://example.com/blog
https://example.com/blog/
https://www.example.com/blog
https://www.example.com/blog/
@RoxanaStingu
> Duplicate content
### Turn on rewrite engine
RewriteEngine on
### Force WWW
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
### Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
### Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.example.com/$1 [L,R=301]
.htaccess
@RoxanaStingu
> Duplicate content
Request http://example.com/folder/
Step 1 http://www.example.com/folder/
Step 2 https://www.example.com/folder/
Step 3 http://www.example.com/folder
Step 4 https://www.example.com/folder
@RoxanaStingu
#### Force HTTPS://WWW and remove trailing / from files ####
## Turn on rewrite engine
RewriteEngine on
# Force HTTPS and WWW
RewriteCond %{HTTP_HOST} !^www.(.*)$ [OR,NC]
RewriteCond %{https} off
RewriteRule ^(.*)$ https://www.example.com/$1/ [R=301,L]
# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^https://www.example.com/%1 [R=301,L]
# Include trailing slash on directory
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ https://www.example.com/$1/ [R=301,L]
.htaccess
@RoxanaStingu
> Duplicate content
Request http://example.com/folder
Step 1 https://www.example.com/folder/
Request https://www.example.com/folder
Step 1 https://www.example.com/folder/
@RoxanaStingu
> SEO-Friendly URLs
https://cdn03.example.com/8cb42/index.php?35872=8zh3n
https://example.com/?q=node/7
https://example.com/index.php?p=4556
https://www.example.com/index.html
@RoxanaStingu
> Remove file extensions
@RoxanaStingu
> Consolidate index pages
@RoxanaStingu
> Lowercase URLs
@RoxanaStingu
> Lowercase URLs
@RoxanaStingu
……….
@RoxanaStingu
TTFB
> Performance issues
@RoxanaStingu
1 2 3 4 5 6 7 8 9 10 11 12 13 14
4.6
4.8
5
5.2
5.4
5.6
5.8
6
0
100
200
300
400
500
600
700
800
1 2 3 4 5 6 7 8 9 10 11 12 13 14
PageLoadTime(s)
TTFB(ms)
.htaccess no. of redirects
Impact of .htaccess rules on page load time
Series2 Series3
Thanks to SEOMike
@RoxanaStingu
0
500
1,000
1,500
2,000
2,500
3,000
1 2 3 4 5 6 7
TTFBinMS
# of lines in .htaccess
TTFB of a 280 byte .txt file
Thanks to Simon Thompson
@RoxanaStingu
COMPOUND
COMPOUNDED EFFECT
DUE TO MULTIPLE
RESOURCES
@RoxanaStingu
> File size issue?
1M Redirect
Directives
58.9MB
4.247s TTFB
1M Commented Lines
59.9MB
0.393s TTFB
@RoxanaStingu
> Warning
@RoxanaStingu
CUSTOM ERROR
PAGES
@RoxanaStingu
> Soft 404 Errors
@RoxanaStingu
> 404 pages
@RoxanaStingu
PAGE SPEED
@RoxanaStingu
> Leverage Browser caching
Cache control
Expires headers
@RoxanaStingu
# Set the cache-control max-age
# 1 year
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>
# 2 DAYS
<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
### Set Expires Headers
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Expires
"Thu, 15 Jan 2015 20:00:00 GMT"
</FilesMatch>
.htaccess
@RoxanaStingu
> Enable Keep Alive
.htaccess
# TN START ENABLE KEEP ALIVE
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
# TN END ENABLE KEEP ALIVE
@RoxanaStingu
> Deflate compression
.htaccess
# TN START DEFLATE COMPRESSION
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE "application/atom+xml" 
"application/javascript" 
"application/json" 
"application/ld+json" 
"application/manifest+json" 
"application/rdf+xml" 
"application/rss+xml" 
"application/schema+json" 
"application/vnd.geo+json" 
"application/vnd.ms-fontobject" 
"text/xml"
</IfModule>
# END DEFLATE COMPRESSION
@RoxanaStingu
> Gzip compression
.htaccess
# TN START GZIP COMPRESSION
<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_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# TN END GZIP COMPRESSION
@RoxanaStingu
> Disable Image Hotlinking
.htaccess
# TN – DISABLE IMAGE HOTLINKIING START
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mywebsite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?google.com [NC]
RewriteRule .(jpeg|gif)$ https://www.mywebsite.com/stop-hotlinking.gif [NC,F,L]
# TN – DISABLE IMAGE HOTLINKIING END
@RoxanaStingu
> mod_pagespeed
.htaccess
# TN – ENABLE MOD PAGESPEED START
# COMBINE CSS, COMPRESS IMAGES, REMOVE HTML WHITE SPACE AND COMMENTS
<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters rewrite_css,combine_css
ModPagespeedEnableFilters recompress_images
ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>
# TN – ENABLE MOD PAGESPEED END
@RoxanaStingu
CRAWLING &
INDEXING
@RoxanaStingu
> Canonical tags
### Add a canonical tag to a non-HTML resource
<Files white-paper.pdf>
Header add Link '<https://www.example.com/white-paper-download.html>;
rel="canonical"'
</Files>
.htaccess
@RoxanaStingu
> Indexing directives
### Add a meta robots tag to a non-HTML resource
<Files white-paper.pdf>
Header add X-robots-tag "noindex, noarchive, nosnippet"
</Files>
### Add meta robots tags to non-HTML resources by type
<Files ".(docx|pdf)$">
Header add X-robots-tag "noindex, noarchive, nosnippet"
</Files>
.htaccess
@RoxanaStingu
TOOLS &
RESOURCES
@RoxanaStingu
> Getting to grips with .htaccess
danielmorell.com/guides/htaccess-seo
.htaccess for SEO
@RoxanaStingu
> .htaccess generators/testers
aleydasolis.com/htaccess-redirects-generator/
danielmorell.com/tools/htaccess/redirect-generator
htaccesscheck.com
webconfs.com/seo-tools/htaccess-301-redirect-tool/
htaccesstools.com
@RoxanaStingu
> Thank you!

More Related Content

PPTX
Product, service and category page links (and how to get them) - Rebecca Moss...
PDF
The Hidden Gems of Low search volume
PDF
Python For SEO specialists and Content Marketing - Hand in Hand
PDF
Developing Technical SEO Skills - Brighton SEO Sept 2021
PPTX
Brighton SEO - Luis Bueno Tabernero - How to do an ASO Audit like in the 90's...
PDF
Improving Crawling and Indexing using Real-Time Log File Insights
PPTX
How to leverage indexation tracking to monitor issues and improve performance
PDF
SEO for E-commerce in 2020 - Top Technical SEO Challenges & How to Fix them #...
Product, service and category page links (and how to get them) - Rebecca Moss...
The Hidden Gems of Low search volume
Python For SEO specialists and Content Marketing - Hand in Hand
Developing Technical SEO Skills - Brighton SEO Sept 2021
Brighton SEO - Luis Bueno Tabernero - How to do an ASO Audit like in the 90's...
Improving Crawling and Indexing using Real-Time Log File Insights
How to leverage indexation tracking to monitor issues and improve performance
SEO for E-commerce in 2020 - Top Technical SEO Challenges & How to Fix them #...

What's hot (20)

PDF
How to Grow your Organic Search Traffic in International Markets #ConnectaBern
PPTX
Don't be a cannibal
PDF
How to automate a long tail SEO strategy for ecommerce
PDF
How to Implement Machine Learning in Your Internal Linking Audit - Lazarina S...
PPTX
EAT: Have We Been Looking At It Backwards
PDF
SEO Audits that Maximize Growth #SMXL19
PDF
[BrightonSEO October 2022] On-page SEO: from intention to conversion
PDF
How to control googlebot
PPTX
Beth Barnham Schema Auditing BrightonSEO Slides.pptx
PDF
The Worst SEO Issues of Online Stores in 2022 & How to Fix Them #YoastCon2022
PDF
SEO low hanging Fruit - Identifying High Impact Opportunities Fast #SEOforUkr...
PDF
A Simple method to Create Content using NLP
PDF
How to Make SEO Audits That Matter & Get Implemented for SEO Success - The Ex...
PPTX
10 Mistakes in 10 Years in SEO - Patrick Langridge
PDF
Why the f*ck Doesn't This HREFLANG Work - BrightonSEO Autumn 2021
PDF
Analisis de Contenidos SEO: método Triple A #SEOnderground 2022
PDF
Winning SEO when doing Web Migrations #SEO4Life
PPTX
Why Scaling (Great) Content Is So Bloody Hard
PDF
The SEO Guide to Migrate International Websites #SMProfs
PPTX
Brighton SEO April 2022 - Automate the technical SEO stuff
How to Grow your Organic Search Traffic in International Markets #ConnectaBern
Don't be a cannibal
How to automate a long tail SEO strategy for ecommerce
How to Implement Machine Learning in Your Internal Linking Audit - Lazarina S...
EAT: Have We Been Looking At It Backwards
SEO Audits that Maximize Growth #SMXL19
[BrightonSEO October 2022] On-page SEO: from intention to conversion
How to control googlebot
Beth Barnham Schema Auditing BrightonSEO Slides.pptx
The Worst SEO Issues of Online Stores in 2022 & How to Fix Them #YoastCon2022
SEO low hanging Fruit - Identifying High Impact Opportunities Fast #SEOforUkr...
A Simple method to Create Content using NLP
How to Make SEO Audits That Matter & Get Implemented for SEO Success - The Ex...
10 Mistakes in 10 Years in SEO - Patrick Langridge
Why the f*ck Doesn't This HREFLANG Work - BrightonSEO Autumn 2021
Analisis de Contenidos SEO: método Triple A #SEOnderground 2022
Winning SEO when doing Web Migrations #SEO4Life
Why Scaling (Great) Content Is So Bloody Hard
The SEO Guide to Migrate International Websites #SMProfs
Brighton SEO April 2022 - Automate the technical SEO stuff
Ad

Similar to .htaccess for SEOs - A presentation by Roxana Stingu (20)

PDF
How I learned to stop worrying and love the .htaccess file
PDF
Great+Seo+Cheatsheet
PPT
Advanced SEO for Web Developers
PPT
Getting More Traffic From Search Advanced Seo For Developers Presentation
PPTX
Web Front End Performance
PPTX
The Need for Speed - SMX Sydney 2013
PDF
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
PDF
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
PDF
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
PPT
Heavy Web Optimization: Frontend
PPT
腾讯大讲堂09 如何建设高性能网站
PPT
腾讯大讲堂09 如何建设高性能网站
PPT
04 Architecting Navigation
PPTX
2018 Google Mobile First Index - Speed up Apache & Web for SEO
PPTX
Hardcode SEO
PDF
SEO for Developers
ODP
A Holistic View of Website Performance
PDF
Amp your site: An intro to accelerated mobile pages
PPTX
PDF
WordPress At Scale. WordCamp Dhaka 2019
How I learned to stop worrying and love the .htaccess file
Great+Seo+Cheatsheet
Advanced SEO for Web Developers
Getting More Traffic From Search Advanced Seo For Developers Presentation
Web Front End Performance
The Need for Speed - SMX Sydney 2013
Leverage HTTP to deliver cacheable websites - Codemotion Rome 2018
Leverage HTTP to deliver cacheable websites - Thijs Feryn - Codemotion Rome 2018
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
Heavy Web Optimization: Frontend
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
04 Architecting Navigation
2018 Google Mobile First Index - Speed up Apache & Web for SEO
Hardcode SEO
SEO for Developers
A Holistic View of Website Performance
Amp your site: An intro to accelerated mobile pages
WordPress At Scale. WordCamp Dhaka 2019
Ad

More from Roxana Stingu (7)

PPTX
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
PPTX
The internet for SEOs by Roxana Stingu
PPTX
Web core vitals and the performance report by Roxana Stingu
PPTX
How to optimise TTFB - BrightonSEO 2020
PPTX
Product Image Optimisation
PPTX
How to keep your WordPress websites fast for users and search engines alike
PPTX
WordPress optimisation beyond the Yoast plugin by Roxana Stingu - 123 Reg
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
The internet for SEOs by Roxana Stingu
Web core vitals and the performance report by Roxana Stingu
How to optimise TTFB - BrightonSEO 2020
Product Image Optimisation
How to keep your WordPress websites fast for users and search engines alike
WordPress optimisation beyond the Yoast plugin by Roxana Stingu - 123 Reg

Recently uploaded (20)

PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
artificial intelligence overview of it and more
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Sims 4 Historia para lo sims 4 para jugar
PPT
tcp ip networks nd ip layering assotred slides
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPTX
E -tech empowerment technologies PowerPoint
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Testing WebRTC applications at scale.pdf
PDF
The Internet -By the Numbers, Sri Lanka Edition
WebRTC in SignalWire - troubleshooting media negotiation
artificial intelligence overview of it and more
Paper PDF World Game (s) Great Redesign.pdf
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Module 1 - Cyber Law and Ethics 101.pptx
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Sims 4 Historia para lo sims 4 para jugar
tcp ip networks nd ip layering assotred slides
SAP Ariba Sourcing PPT for learning material
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PptxGenJS_Demo_Chart_20250317130215833.pptx
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
introduction about ICD -10 & ICD-11 ppt.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
E -tech empowerment technologies PowerPoint
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Testing WebRTC applications at scale.pdf
The Internet -By the Numbers, Sri Lanka Edition

.htaccess for SEOs - A presentation by Roxana Stingu