Reputation: 43
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.
Upvotes: 4
Views: 1573
Reputation: 1
Best practice: 301 redirects from HTTP to HTTPS (standard domain). In my case for me, this is the best.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^108\.161\.161\.46
RewriteRule (.*) https://ayuda.ml/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 404.php?%{QUERY_STRING} [NE,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
Upvotes: -1
Reputation: 270
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]
Upvotes: 2