Wordpress SSL issue for addon domains in htaccess - wordpress

I have an wp installation on the main domain and a few addon domains which are unrelated.
I installed really simple ssl plugin to handle all un-secure requests made by my site, but all the addon domains are affected and they require also ssl certificate.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ https://www.example.com/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN rlrssslReallySimpleSSL rsssl_version[2.2.10]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
Without the Really simple ssl it works ok, but this part of the htaccess file affects all subdomains. Also i tried to add
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
in the ssl conditions but now all addon domains are redirected to the main domain.

Try this .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /WORDPRESSROOT/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /WORDPRESSROOT/index.php [L]
</IfModule>
# END WordPress
# BEGIN rlrssslReallySimpleSSL rsssl_version[2.2.10]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
Change WORDPRESSROOT to the folder where your wordpress is located otherwise delete it and change it to /index.php
I also use Really Simple SSL but it only affects the folder where the .htaccess is located in. Otherwise try to move your website to /wordpress/ and redirect your site to your root folder.
Here's the documentation:
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
EDIT: SAVE YOUR OLD .HTACCESS FIRST.

Related

htaccess redirects only with hard refresh

I have a site in React.js on http://example.com, which uses wordpress API, which is located in example/wp subfolder.
I have one htaccess in root folder:
# BEGIN redirection to https
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END redirection to https
# BEGIN needed for client side routing
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ / [L,QSA]
</IfModule>
# END needed for client side routing
and in example/wp another htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
The problem appeared after switching to https. When accessing example/wp/wp-admin I get notFound page from react app instead of wordpress admin panel. But when I hard refresh the page, I get redirected to the admin panel.
Why?
When I add
RewriteCond %{REQUEST_URI} ^.*/testingurl
RewriteRule ^(.*)$ https://someOtherexample.com [R=301,L]
I also get example/testingurl, but after hard refreshing I get redirected to someOtherexample.com.
What I am missing?

Redirect 2 folders from https to http on WordPress

My WordPress hosted website is in https, but I want to remove https for two folders as I need to run http pages inside that pages using iframe. I have tried editing in .htacess file, but nothing worked.
I have tried using PHP code too, nothing worked.
Here is my .htacess file
<IfModule mod_rewrite.c><br>
RewriteEngine On<br>
RewriteCond %{HTTPS} off<br>
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]<br>
</IfModule><br>
SetEnv PHPRC /home/mysitename/public_html/php.ini<br>
# BEGIN WordPress<br>
<IfModule mod_rewrite.c><br>
RewriteEngine On<br>
RewriteBase /<br>
RewriteRule ^index\.php$ - [L]<br>
RewriteCond %{REQUEST_FILENAME} !-f<br>
RewriteCond %{REQUEST_FILENAME} !-d<br>
RewriteRule . /index.php [L]<br><br>
</IfModule>
# END WordPress
# This entry meant for .htaccess file
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} / [NC]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,NE]
RewriteRule (.*) /index.php [L]
# RewriteRule (.*) /folder/path [L]

My https website is redirecting to my old http website

a while ago i made a copy of my wordpress website and restore it on a ssl/https verficated account and since that, my new site have been redirecting to http.
I've tried with the htaccess code and it doesn´t work. I'll paste my code below:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://voladurascontroladas.com/$1 [R,L]
# BEGIN rlrssslReallySimpleSSL rsssl_version[2.5.20]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTPS_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# 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

301 Redirect for All Subdirectories

I am changing domain names for a WordPress site and want to set up a structure like so:
If a user accesses olddomain.com/page, he will be re-directed to newdomain.com/page, etc. In other words, only the pre-slash part of the domain would change. I want to do this for all pages under the old domain.
So far, I have only been able to get olddomain.com to re-direct to newdomain.com, but not any of the sub-directories (for example, olddomain.com/page does not re-direct to newdomain.com/page). Here is my .htaccess file:
# BEGIN GD-SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^newdomain\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END GD-SSL
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]
Does anyone know what I did wrong?
You must put all of the redirect rules before your routing rules. The wordpress rules route everything to index.php, including anything you intend to redirect. So the redirects must happen before any sort of internal routing happens.
Simply put your redirect rule before the wordpress rules:
# BEGIN GD-SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^newdomain\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END GD-SSL
RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]
# 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
Change your .htaccess to the below code on the old domain:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.olddomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
</IfModule>
This will redirect the entire website on a page by page basis.

wordpress http to https redirect loop

I am trying to force my site to load in HTTPS. I can create a redirect in PHP which works for PHP files, but I want all requests forced to HTTPS - JS, CSS, Images, etc.
Here's what I have in my .htaccess:
ErrorDocument 401 default
# 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
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I have tried various methods of this by placing the redirect in different locations and such, but everything seems to make this into a redirect loop. Any ideas what I could do to fix that?
Thank you.
Keep your http to https rules before internal WP rule:
ErrorDocument 401 default
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Make sure WP's home URL and site URL also have https in permalink settings.
Set a 301 permanent redirect which is more SEO friendly. Already tested:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all traffic to https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Wordpress rules
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Resources