How Correctly Set-Up The 301 Redirect Only for Main Website Page

July 7, 2019 325 views
Apache DigitalOcean Solutions WordPress Ubuntu 18.04

Hi everyone,

I need help with not easy redirect situation regarding my two websites:

So currently I have one website that works for example on this address:

https://www.test.org/ - on the general WordPress website setting I have the same address: https://www.test.org/

Also in this file 000-default.conf (folder site enabled) on FTP I have those lines:

# Added to mitigate CVE-2017-8295 vulnerability
UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        ServerName test.org
        ServerAlias www.test.org

        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.test.org [OR]
RewriteCond %{SERVER_NAME} =test.org
RewriteRule ^ https://www.%1%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

the main question is how I can set-up 301 redirects only from this http://www.test.org/ main page to another website main page?

means that all rest scenario like those:

from https://test.org/ to https://www.test.org/
from http://test.org/ to https://www.test.org/

should continue working as it was in this code:

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.test.org [OR]
RewriteCond %{SERVER_NAME} =test.org
RewriteRule ^ https://www.%1%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Many thanks

2 Answers

Hello,

Can you please clarify a little bit?

From what you’ve posted above, if you add the redirect like that you would have the following redirect chain:

http(s)://test.org/ –> https://www.test.org/ –> another-website.com

So no matter if you access http://test.org/ or https://www.test.org/ you would always be redirected to the other site.

You could for example redirect your home page to another domain and leave all subpages without a redirect. So the redirect chain would be something like this:

http(s)://(www.)test.org –> another-website.com

http(s)://(www.)test.org/*all-other-pages* - load as normal

Regards,
Bobby

Bobby hi,

I know this fact: So no matter if you access http://test.org/ or https://www.test.org/ you would always be redirected to the other site.

The main issue here is that facts that all previous external backlinks was pointed to this domain name http://www.test.org/ and now we have to much redirect chains in order to transfer all those ref. domains to another websites via 301 redirects (google not in such good way see all those backlinks) as it will be redirect directly from first old url like this one for example http://www.test.org/ directly to another our website.

So means that we would like to test this situation and set-up redirect directly from old one main page like this one http://www.test.org/ to new website with only one redirect chain - without this scenario:

http://www.test.org/ - to https://www.test.org/ and to the new website.

I hope you understand our needs.

Many thanks.

Have another answer? Share your knowledge.