Home Htaccess URLs redirects are working for http not all https
Reply: 1

Htaccess URLs redirects are working for http not all https

Frost
1#
Frost Published in 2018-01-11 11:26:58Z

newbie on htaccess and redirects, I hope someone can help me with this. At the moment all the http urls are redirecting correctly. E.g. if you go to otherdomain.com it will take you to the maindomian.com.

This is currently not working for all of the https links.

For example: http - both www and non www otherdomain.com/blog will redirect to https://www.mainwebsite.com/blog

Which is what I need, however as soon as I get to the https it does the following:

https - both www and non www otherdomain.com/blog will remain on the https otherdomain.com/blog domain.

Which is wrong because it needs to go to the main website's blog page. But if I have manually added a redirect on a page all the http and https urls will work: E.g. both www and non www http://www.otherdomain.com/newpage will redirect to https://www.mainwebsite.com/welcome https://www.otherdomain.com/newpage will redirect to https://www.mainwebsite.com/welcome

It's Drupal 7, here is the code that I currently have:

Redirect /newpage                                       https://www.mainwebsite.com/welcome


    RewriteEngine on
    RewriteBase /

    # Force HTTPS 
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # Remove trailing slash
    RewriteRule ^(.*)/$ https://%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{HTTP_HOST} ^mainwebsite.com$ [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Set "protossl" to "s" if we were accessed via https://.  This is used later
    # if you enable "www." stripping or enforcement, in order to ensure that
    # you don't bounce between http and https.
    RewriteRule ^ - [E=protossl]
    RewriteCond %{HTTPS} on
    RewriteRule ^ - [E=protossl:s]

    # Make sure Authorization HTTP header is available to PHP
    # even when running as CGI or FastCGI.
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

        # Pass all requests not referring directly to files in the filesystem to
    # index.php. Clean URLs are handled in drupal_environment_initialize().
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^ index.php [L]

Any idea how I can get any url from the https otherdomain.com to go to the mainwebsite.com? Any help would be greatly appreciated.

Emir Memic
2#
Emir Memic Reply to 2018-01-12 16:06:56Z
RewriteEngine on
RewriteCond %{HTTP_HOST} ^othersite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.othersite.com [NC]
RewriteRule ^(.*)$ https://www.mainwebsite.com/$1 [L,R=301,NC]

That will redirect all requests, not just /blog

if you want just /blog to redirect then I would adjust the RewriteRule a little

RewriteRule ^blog/?$ http://www.newsite.com/blog [L,R=301,NC]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.324432 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO