E
E
Eugene2017-01-10 16:20:49
htaccess
Eugene, 2017-01-10 16:20:49

How to correctly set up a redirect from http and / or without www to https from www, at the same time, so that redirects do not affect the robots.txt file?

Hello,
The goal is to set up a redirect from the following pages:
site.ru | www.site.ru | https://site.ru
to https://www.site.ru , while it is necessary to exclude the redirect for some pages, for example: robots.txt
Currently works with the following structure, but it seems to me that this can be described more competently. Anyone with knowledge of the matter can advise?

RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml|sitemap\.php)$
RewriteCond %{HTTP_HOST} !^www\.site\.com$ [NC]
RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml|sitemap\.php)$
RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zooks, 2017-01-10
@zooks

RewriteEngine On
RewriteBase /

# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
#RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]

# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com/$1 [R=301,L]

https://github.com/modxcms/revolution/blob/2.x/ht....
I never make exceptions for robots.txt and this does not lead to a decrease in positions.

N
Neocaridina, 2017-01-11
@Neocaridina

301 for everything, no exceptions.
Redirect is more priority than robots for all PS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question