Redirect wordpress subdomain fails with /admin - wordpress

I have a wordpress installed in my public_html under the foo.com domain. I've installed a new wordpress site under public_html/bar under the bar.com domain. I have the following htaccess files:
public_html:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?bar.com$
RewriteCond %{REQUEST_URI} !^/bar/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /bar/$1
RewriteCond %{HTTP_HOST} ^(www.)?bar.com$
RewriteRule ^(/)?$ bar/index.php [L]
</IfModule>
When I tried to enter to bar.com, the site displays correctly. But when I try to enter bar.com/admin the site redirects me to foo.com/wp-login. Is there any additional config tha I'm missing?

Related

.htaccess wordpress - rewrite subdomains to main domain

I have a wordpress site with the wordpress files in a different folder (wpaw)
Wordpress url https://example.com/wapw
Site url https://example.com
I also have 3 or 4 subdomains, for example new.example.com
Currently the main domain and all the subdomains work correctly with the following RewriteRule
RewriteEngine On
RewriteRule %{REQUEST_URI} !^/wpaw/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wpaw/$1
RewriteRule ^(/)?$ /wpaw/index.php [L]
How can I modify the above so that http(s)://anysubdomain.example.com also redirects to https://example.com
Please write the below code in .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteEngine On
RewriteCond %{HTTP_HOST} ^anysubdomain\.example\.com [NC]
RewriteRule ^(.*) https:/.example.com/$1 [L,R=301]
</IfModule>
Thanks

How to correctly redirect Wordpress in subdirectory with https?

I have an issue with Wordpress installed in subdirectory of root and https.
The most I could get is to have frontend fully working over https, but the /wp-admin cannot be accessed due to redirection loop.
my wp current setup:
FTP root structure:
/.htaccess
/main-domain.com (WP folder with same name as the domain name)
/subsite-1.main-domain.com (3rd level domains, no connection to WP)
/subsite-2.main-domain.com
/...
root .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?main-domain.com$
RewriteCond %{REQUEST_URI} !^/main-domain.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /main-domain.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?main-domain.com$
RewriteRule ^(/)?$ main-domain.com/index.php [L]
# subdomain redirects
RewriteCond %{HTTP_HOST} ^subsite-1.main-domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subsite-1.main-domain.com/.*$
RewriteRule ^(.*)$ /subsite-1.main-domain.com/$1 [L]
wordpress .htaccess (/main-domain.cz/.htaccess)
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
/main-domain.com/wp-config.php
define('WP_SITEURL','https://main-domain.com');
define('WP_HOME','http://main-domain.com');
// with WP_HOME set to "https://..." the site falls to redirection loop
I guess I just can't get my htaccesses straight, but also I'm afraid I'm "fighting" with WP internal redirects.
Two main things I want to achieve is the site to always be redirected to https and the folder name (/main-domain.com/) not to be seen in URL

Homepage doesn't redirect from HTTP to the HTTPS same page

Here's my website structure :
/public_html
/subdir
/wordpress website
My main domain was on public_html and I move the whole to the subdir with this htacess in the root (public_html) (from Wordpress Codex):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdir/index.php [L]
</IfModule>
When I access to example.com or www.example.com (without https), it redirects to : https://example.com/subdir
When I access to example.com/page1, it redirects well to https://example.com/page1
It's a bit annoying. How can I resolve this please ?
Thanks
Finally it's ok
This was due to the SSL redirect code in the public_html/subdir/.htaccess files:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I moved this code to public_html/.htaccess and the site is now working as expected.

Wordpress redirection loop error

I created a website few days back with a url http://abctest.com in wordpress. Now the website has been published to a domain http://www.bcdefg.com.
The server is same, I have not migrated the site, only the domain has been pointed to the same server. I have changed the wphome and wpsite url to respective domain.
What I want to achieve is to redirect all http://abctest.com or http://www.abctest.com requests to http://www.bcdefg.com.
I tried to use .htaccess redirection but that leads to Too many redirection error. Any solution ?
Below is my htaccess code.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
RewriteRule ^(.*)$ http://www.bcdefg.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Error is on your rewriteCond : your host is www.bcdef.com and not bcdef.com (www is important)
try replacing this
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
by this :
RewriteCond %{HTTP_HOST} !www.bcdefg.com$ [NC]

wildcard ssl .htaccess file causes 500 error on laravel subdomain

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]

Resources