wordpress multisite domain mapping redirects - wordpress

I just added a new site to my wordpress multisite and if www wasnt in front of the url, it redirected to my main site.
i added the following code to my htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
and now my secondary site works just fine, however my main site now redirects to the secondary one.
does anyone have any suggestions for me?
thanks

Yours will rewrite any URL without www.example.com to the new domain.
This worked for me, to rewrite all non www to example.com.
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]
Also, for some reason, I needed to refresh the permalinks in the child site as well.

Related

Why is my subdomain redirecting to my main domain

I have a subdomain https://app.freewebcart.com
example -- open this link https://app.freewebcart.com then click any of the post that post redirect to main domain
Here is my .htaccess
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com\$ [NC]
RewriteCond %{HTTP_HOST} !^app\.mydomain\.com\$ [NC]
RewriteRule ^(.*)$ http://www.mydomai.com./$1 [R=permanent,L]
It is possible your wordpress install is pointing to the main URL via WP_SITEURL and WP_HOME. Have a look at this website with instructions on how to check and make the relevant changes.
Reference: https://wordpress.org/support/article/changing-the-site-url/

Add Subdomain to Wordpress main site

So my main domain is build on the wordpress platform. I have build a custom website which is NOT build on a wordpress platform. All I am trying to do is host the site I build on a subdomain. Thus it should look like this:
www.subsomain.maindomain.com
I have uploaded my files to the subdomain folder and all is working.
MY PROBLEM
My site works fine when entering subdomain.maindomain.com i.e. without the www version.
However as soon as I try to redirect my site to www.subdomain.maindomain.com I get a DNS SERVER NOT FOUND error.
So my NON www version works but when I try to run the WWW version it does not work.
What I have done.
Redirect the subdomain to www version in Cpanel (didnt work)
Change the.htaccess file, tried multiple tweaks and changes (didnt work)
I called godaddy the agent told me because the main site runs on wordpress platform I would need to go into the mainsites wordpress database and make changes there for the www version of subdoman to work...? (is this correct, it doesnt make sese to me..?)
Here is my current .htaccess
RewriteEngine on
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect to another domain: example.com.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule .* http://example.com%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule .* https://example.com%{REQUEST_URI} [R=301,L]
All I want to do is redirect my subdomain to www version Any help appreciated
It doesn't work because www.subsomain.maindomain.com doesn't exist. You have to add a CNAME record in your zone subsomain.maindomain.com the same way you've added the host subdomain to maindomain.com.

Redirect Wordpress Site (HTACCESS) to new domain, but with certain exceptions

I'm trying to figure out the best way to redirect a client site to a new blog. They have a Wordpress installation, which they want to redirect to a new Wordpress site. The issues are they want to redirect everything, but four posts, to the root of the new domain. The four posts have corresponding ones on the new blog, so
olddomain/setting-goals/ redirects to newdomain/setting-goals/
The same goes for three other posts, but I can't put them here due to reputation rules.
My issue comes in how can I do the redirect of four posts to their corresponding ones on the new domain and also redirect everything else (including home page) to the root of the new domain?
A caveat is they want to still be able to access their Wordpress admin panel on the old domain, so wp-login.php and the /wp-admin/ folder.
I tried this code in htaccess on top of the default Wordpress redirect, but it didn't work for me. I just wanted to see if I can get one of the redirects working correctly. It was just redirecting the setting-goals/ to the root of the new domain:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/setting-goals/ [NC]
RewriteRule ^setting-goals/(.*)$ http://www.newdomain.com/$1 [L,R=301]
RewriteRule (.*) http://www.newdomain.com? [R=301,L]
You can use for 4 rules like below to redirect to their exact URL on the newdomain. Then redirect everything else if it's not wp-login.php or wp-admin.
RewriteEngine on
RewriteRule ^(setting-goals)/?$ http://www.newdomain.com/$1 [L,R=301]
RewriteRule ^(setting-goals2)/?$ http://www.newdomain.com/$1 [L,R=301]
RewriteRule ^(setting-goals3)/?$ http://www.newdomain.com/$1 [L,R=301]
RewriteRule ^(setting-goals4)/?$ http://www.newdomain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin(.*)?)$
RewriteRule ^(.*)$ http://www.newdomain.com/? [R=301,L]

htaccess redirect not redirecting all pages

I am trying to implement an htaccess redirect and it is partially working. It will redirect the root domain http://oldsite.com/ to http://newsite.com/. However, when I try and do more such as http://oldsite.com/eng it will not redirect. Here is my htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newsite.com/$1 [R=301,L]
This is from a wordpress site that had two domains that pointed to the same folder on the server (same wordpress instance). We now want to phase out the old domain so whatever link you go to on http://oldsite.com/ will redirect to the correct part of http://newsite.com/.
You should try and check for the old host before doing the redirect. If it's on the same server it will cause problems without it.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite.com [NC]
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]

Redirect loop from old domain to new subdomain

I have an issue with .htaccess rewrite ruleset. www.OldDomain.com with Joomla template is being retired and new website is a Wordpress based site having address at http://newdomain.com/subfolder.
For some reason I get the following message: "This webpage has a redirect loop", but whatever I try it doesn't work. The new Wordpress site has url-friendly links generated by wordpress. I tried to upload a default wordpress .htaccess but it doesn't work either.
Can anyone point me in right direction how to solve this issue? Thank you in advance.
The old site was on a different server with the same domain name as the new one.
Current .htaccess file on a domains' new server is as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^newdomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
RewriteRule ^$ beta/ [L]
You can use the following :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/beta/$1 [L,R=301]

Resources