I have several sites as sub-domains with a main domain called site1.com. My main domain has a wildcard ssl certificate for *.site1.com. My subdomains can be referenced as site2.site1.com, site3.site1.com to siteN.site1.com. My main domain uses the certificate correctly and forces https on all pages, my subdomains only use https on the admin pages, I'm using a wordpress CMS or I can force the certificate to be used if I reference my sites as https://site2.site1.com, https://site3.site1.com etc. I want to get my subdomains running as https://site2.com. Currently my domain works as http://site2.com or http://site1.site2.com
PS: I have no access to the vhost file. Here is my .htaccess code for all my domains:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
</IfModule>
I found a simple plugin that did the job for me. This is what my .htaccess file looks like now for my sub-domain:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
#RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
</IfModule>
Related
Pages on our WordPress site are not automatically redirecting to the HTTPS version even though we have set the site url and home url to use HTTPS.
This is the code we have at the top of our wp-config.php file:
define('WP_HOME','https://webwisemedia.co.uk');
define('WP_SITEURL','https://webwisemedia.co.uk');
define('FORCE_SSL_ADMIN', true);
Our .htaccess file looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If you visit a page on our site, like http://webwisemedia.co.uk/web-wise-in-the-press/, it doesn't redirect to the HTTPS version.
Any ideas why?
You mixed up the Wordpress part of .htaccess and that is why it isn't working. That part is changed every time you update, for example, permalinks. Your .htaccess should look like this:
# Rewrite HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This leaves the Wordpress part intact and it forces to use https. From now on if you change anything in .htaccess do it below the Wordpress part.
I have a wildcard ssl installed on my account (My host is Bluehost) and I followed the directions here from Bluehost's site to install the wildcard SSL. However, when I try and access the site at all it comes up with a 500 internal server error. I am using laravel framework right now for the subdomain, I don't know if that changes anything, but here is the .htaccess file for the main site (Which is a wordpress site):
# Custom subdomain .htaccess SSL + WordPress
RewriteCond %{HTTP_HOST} ^admin.mysite.com$
RewriteCond %{REQUEST_URI} !^/admin/public/
RewriteRule ^(.*)$ /admin/public/$1
RewriteCond %{HTTP_HOST} ^admin.mysite.com$
RewriteRule ^(/)?$ admin/public/index.php [L]
# End custom subdomain .htaccess
# BEGIN WordPress
AddHandler application/x-httpd-php70s .php
<IfModule mod_rewrite.c>
# Custom maindomain .htaccess WordPress
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# End custom maindomain .htaccess
</IfModule>
# END WordPress
And here is the .htaccess file for the subdomain (the one with laravel installed):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Keep in mind too, I know nothing about .htaccess or how it works, I just did what the webpage said to do.
I suggest you to try below code for simple redirection HTTP to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This should work for your main domain and its sub-domain both. Now if you want to redirect Non-WWW domain to WWW then try below code;
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.domainname.com%{REQUEST_URI} [L,R=301]
I'm at a basic level of understanding when it comes to .htaccess redirects but I'm managing to just about get by with a site I'm redeveloping. I have searched Stack Overflow quite extensively, but can't understand how to put together all the advice in the context of my own situation.
I'm switching my WordPress the site to https and so far have managed to cobble together the following set-up:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [NC,R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have a few bugs I'd like to iron out though, currently http:// redirects to https:// which then redirects to https://www.
How do I set up an additional rule to move everything from http:// directly to https://www. ?
Also there are some pages I'd like to redirect to new URLs in the https site. http://www.example.com/bunny to https://www.example.com/rabbit. How is the best way (least 301 chains) to redirect these from insecure to a new secure URL?
I advice you to replace your redirect rules to this (adapt your domain):
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
You don't need to use RewriteCond %{ENV:HTTPS} !=on
You need to something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
and in wp-admin:
wordpress site Address Url : https://Your_site_url
Site Address Url:https://Your_Site_Url
I have a wordpress website somewebsite.com
If I visit it naked like that, it works brilliantly, however if I visit it from www.somewebsite.com I get
Warning: Cannot modify header information - headers already sent by (output started at /home/somewebsite/public_html/index.php:2) in /home/somewebsite/public_html/wp-includes/pluggable.php on line 1121
In the wordpress website general settings it's set to somewebsite.com
and in CPANEL I have the following
an A record with somewebsite.com pointing to the ip address
a CNAME record with www.somewebsite.com pointing to somewebsite.com
Just for kicks I changed the setting in the wordpress general settings to www.somewebsite.com which fixed it for if I was to visit it with the www but broke it for the naked domain, so I switched it back.
my .htaccess looks like
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help would be greatly appreciated
Simple is best :-) Redirect non-www to www or www to non-www using .htaccess, so user is going to be redirected before loading any script in php.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
In your example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Remember to change chmod for .htaccess - it can be overwritten by WordPress in some cases.
I have asked my domain host provider to point a website to my public_html folder. but now I have been told the if I need this other domain to redirect to a particular url on my primary domain website, I would need to do it in the htaccess file. At the moment I have researched and this is what my htaccess looks like without any luck!
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 5
DirectoryIndex index.cgi index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^otherdomain.org.uk
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L]
The above does not redirect my otherdomain.org.uk to the blog page on my primarydomain.org/blog. Please note that my primarydomain.org/blog is a wordpress website page.
Keep redirect rules before your WP rules.
Have your rules like this:
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 5
DirectoryIndex index.cgi index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^otherdomain.org.uk
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress