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.
Related
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.
I have created wildcard subdomains based on username. However it is working fine but only issue which occurs it that its working with double slashes at the end. For example johndoe.example.com// and if i use johndoe.example.com/ it redirects me to main domain example.com. I am not sure why this is happening and what to i have to do in .htaccess file. I tried many things in htaccess but it is not working.
Expected URL - username.example.com
Actual URL - example.com/user/username
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com$ [NC]
RewriteRule ^/?$ /user/%1 [L]
I have recently installed WordPress Certified by Bitnami Application on AWS EC2, I found out the website was loading in 2 diffrent version on with www. one without www.
I found this code after some research and it worked for me
/opt/bitnami/apache2/conf/bitnami/bitnami.conf
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Later I installed letsencrypt SSL on my site, after installing ssl i am facing the same trouble
In order to force load ssl i had to enter below code in same file
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https/www.xyz.com/$1 [R,L]
Please Help
Having an issue with some url rewrites.
I want to redirect all urls to https with no www
Currently I have :
1) Forces https with the (s) - working
http://example.com => https://example.com
2) Forces https with the (s) and removes www - working
http://www.example.com => https://example.com
3) Remove the www from the https with the (s) requests - failing
https://www.example.com => https://example.com
It seems as if it's not even reaching my htaccess code with an ERR_SSL_UNRECOGNIZED_NAME_ALERT
Site might be temporarily down or it may have moved permanently to a new web address.
This is what I have in my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
The site is hosted by Host Gator and I contacted support and was told that it's impossible to set this up because the site is built with Wordpress.
That didn't seem like the right answer to me so thought I'd ask here.
Any info appreciated.
Cheers
RewriteCond %{HTTPS} off will not detect HTTPS requests, so you may want to add another rule for HTTPS requests only (with the same/similar conditions), e.g.:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Instead of adding this, you can also simplify everything with an OR condition:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
</IfModule>
Which means, if HTTPS is null or off OR the domain does not start with example.com, redirect to https://example.com.
Amusing that the support believes that Wordpress somehow prevents .htaccess to be used, but I wonder if your host may have certain .htaccess restrictions, preventing plugins that rely on it (e.g. BulletProof Security) to work properly.
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.