简体   繁体   中英

Htaccess URLs redirects are working for http not all https

newbie on htaccess and redirects, I hope someone can help me with this. At the moment all the http urls are redirecting correctly. Eg 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: Eg 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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM