Multisite mapped domain force to use www - wordpress

I am trying to force domain URL to use www always in WordPress Multisite.
For example if some one type abc.com then it should be redirect automatically to www.abc.com
I have used the following rules in htaccess but it works only for main domain in WordPress Multisite and not for other sub domains.
# Canonical https/www
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
So any help on this, is highly appreciated in advance.

Can you try this ?
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

Related

.htaccess file exact match and not exact match

I just moved to a WordPress site. I used to have a static site and a WordPress blog on a subdomain (blog.example.com). I'm using the code below, which is redirecting all of my blog posts to my new website perfectly fine. Is there any way to make an exception for the main blog page? To be specific, I need the code below to apply to all my posts, categories, etc. (which it already is), but I need my old blog home page (blog.example.com) to 301 redirect to my new blog homepage (example.com/blog). Just to be very clear, my posts, etc. are NOT using blog in the permalink.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</IfModule>
UPDATE: Thanks, Olaf! Got this working with your advice. Here is my final code for anyone else looking for an answer.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^$ http://www.example.com/blog [R=301,L]
RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</IfModule>
Put the most specific rules at the beginning. In your case, prepend the existing rule with the redirect for the main page
RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^$ http://www.example.com/blog [R,L]
When everything works as it should, you may replace R with R=301. Never test with R=301.

Force add 'https://' in my cspecific pages by htaccess

I have a website built with WordPress cms, i want to add https:// on my contact page by htaccess file of website. I have try different think but i an not able to do it. Here is the site link
Please share if have any idea!.
If you have https enabled for your domain, it would be a good idea to use it for the entire website, not just for one/some pages only.
To redirect all existing pages from http to HTTPS, you can use the following .htaccess code snippet:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R,L]
</IfModule>
In your .htaccess - add this logic.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} contact
RewriteRule ^(.*)$ https://alacartesites.com/contact/$1 [R,L]
Ref: http://www.inmotionhosting.com/support/website/ssl/how-to-force-https-using-the-htaccess-file, it worked for me. I verified. Please use the below one.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(contact|contact/)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

http:// to https:// redirect but something is overriding it back to http://

I am trying to redirect my domain
http://atc-logistics.ie
and
http://www.atc-logistics.ie
to
https://www.atc-logistics.ie
My hosting company gave me this code for the .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTPS_HOST} ^atc-logistics.ie [NC]
RewriteRule ^(.*)$ https://www.atc-logistics.ie/$1 [L,R=301]
and are insisting that there this is correct and something else is causing a redirect so it keeps rebounding back to http://atc-logistics.ie. I can't see any other redirects and there are no redirect plugins (Wordpress).
Can anyone let me know if the redirect above is correct? I am really struggling and the hosting company don't seem to be able to help!
The htaccess redirect system I use is this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
And that works fine for me.
It checks if the host does not begin www. and then diverts to the www. address before then checking if the protocol is Secure and then if it is not forces redirect to the HTTPS, using the previously set HOST and URI address values.

Redirect http to https with www

I am trying to find out how to redirect everything (http/ with and without and http: without) to https://www. (with www.)
I know it needs to be written in the .htacess file and I have forces admin to use https in wp-config already. I'm after the exact script to add at the top of my .htacess file please.
I am running on Cpanel. I'm using wordpress and maxcdn with w3cache. maxcdn is already set up for https.
I have found posts on how to write the code but lack the knowledge to create it myself.
Any help is greatly appreciated!
Thanks for your time.
Like Shiv said, .htaccess is definitely the way to go. Here's the complete solution which will redirect to SSL and add www if not present:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301]
I think this might do the trick:
# 301 Redirect 1
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ https://www.domain.com/? [R=301,NE,NC,L]
# 301 Redirect 2
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ https://www.domain.com/? [R=301,NE,NC,L]
Obviously change domain.com to your domain name.

Redirect a wordpress sub-page to a different domain using mod_rewrite

I am trying to mask https://mydomain.com/free to www.myotherdomain.com so that when www.myotherdomain.com or myotherdomain.com is entered it loads the page at mydomain.com but shows myotherdomain.com in the address bar as well as keeps a ssl connection through mydomain.com without having to use an iframe, is this possible, I am fairly new to working with .htaccess and mod_rewrite my .htaccess code is as follows
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} !^javitaonlinecafe\.com$ [NC]
RewriteRule ^(.*)$ http://freejavitacoffee.com [R=301,L]
# END WordPress

Resources