Question

Subdomain redirecting to main site. Possible .htaccess problem?

Typing in my subdomain automatically redirects to my main URL. I am almost positive it is something in my .htaccess file that forces the redirect. I had a lot of trouble setting my site to only use https://, so I think that may be the cause. I created both an A record and CNAME record for the subdomain. I am making a documentation subdomain for my website, (docs.example.com).

My .htaccess file contains the following:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://[my website url is here].com/$1 [L,R=301]
</IfModule>
# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.1]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL

# BEGIN Really_Simple_SSL_SECURITY_HEADERS
<IfModule mod_headers.c>
Header always set Strict-Transport-Security: "max-age=31536000"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy: "no-referrer-when-downgrade"
</IfModule>
# END Really_Simple_SSL_SECURITY_HEADERS
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<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
# Wordfence WAF
<IfModule mod_php5.c>
	php_value auto_prepend_file '/var/www/html/wordfence-waf.php'
</IfModule>
<IfModule mod_php7.c>
	php_value auto_prepend_file '/var/www/html/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
	Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
	Order deny,allow
	Deny from all
</IfModule>
</Files>
# END Wordfence WAF

Also, do I need to configure an SSL cert for my subdomain or will my other cert cover it? Thanks!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

If @nickplatt4,

You are correct, it seems like at the moment you have an 301 redirect from everything to your website in the following block

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://[my website url is here].com/$1 [L,R=301]
</IfModule>

Now, this would only work if you have configured your Apache Vhost file for your subdomain to load from the said directory. If you want your subdomain to load from another place, I’ll recommend creating/changing the Vhost file for your subdomain and use another directory.

If you are unsure how you can do that, I’ll recommend checking out this DigitalOcean tutorial on how to configure Apache Vhost files :

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04

Regards, KDSys