skip to Main Content

I had some issues with my apache configuration and I’m trying to isolate the problem.

I came up with the following lines which are not working :

For testing purposes, I’m trying to redirect all https traffic to Yahoo

The redirection is not working and my web site is showing the index.html file stored in public_html

Listen 443  
NameVirtualHost *:443

<VirtualHost *:443> 
    DocumentRoot "${SRVROOT}/htdocs/example.com/public_html"    
    ServerName example.com
    ServerAlias example
    Redirect permanent / https://www.yahoo.com/
</VirtualHost> 

Can anyone help please ?

Thanks

2

Answers


  1. Use this for the redirect, also enable mod_rewrite for this to work:

    Add this to the top of your .htaccess file:

    RewriteEngine On #Don't use RewriteEngine On twice in one .htaccess file
    RewriteBase /
    RewriteRule ^(.*)$ https://www.yahoo.com [R=301,L]
    

    Clear your browser’s cache to have a different redirect than yahoo.com, once it works.

    Just in case

    If you want all traffic of your website to redirect to https:// on the same domain, do the following, don’t remove RewriteEngine On and RewriteBase /:

    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    

    If you want to redirect all traffic to one domain with https:

    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{HTTP_HOST] !^example.com
    RewriteRule ^(.*)$ https://example.com [R=301,L]
    

    If you want to redirect all traffic to one domain with https and www:

    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{HTTP_HOST] !^www.example.com
    RewriteRule ^(.*)$ https://www.example.com [R=301,L]
    
    Login or Signup to reply.
  2. RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search