XF .htaccess not allowing subdomains

mauzao9

Well-known member
Hello,

So I use Xenforo default htaccess on the main domain but I want to do a test subdomain to run a private install of xF, but every I try, it does redirect the sub.domain.com/url to domain.com/url, I searched a to fix it and instead caused a refresh loop.

Code:
#       Mod_security can interfere with uploading of content such as attachments. If you
#       cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#       SecFilterEngine Off
#       SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
        RewriteEngine On

RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
        RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L,QSA]

RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://domain.com/$1 [NC,L,R]

What do I change to have it cope with a sub-domain?
 
I can't even think of NGINX I'm too used to this setup, just not the madness that .htaccess rules are. o_O
I meant that I use NGINX. Left out the I in that first.... and that was the reason that the second part was an interrogative as my familiarity with .htaccess is from years ago.
 
I had this problem with the full-friendly URL option and this thread helped me:
It was also related to the .htaccess
 
A little hint because the article is older. The Apache2 default configs are now at /etc/apache2/ and you need the file in /etc/apache2/sites-enabled (ofc depends on your version)
 
This is causing it:
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://domain.com/$1 [NC,L,R]

If you want to support sub-domains, you need to specifically carve out www for that redirect, and not all subdomains

# Rewrite www
RewriteCond %{HTTPS} ^on$
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [NC,L,R=301]

# Rewrite other sub-domains
RewriteCond %{HTTPS} ^on$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteRule ^(.*)$ http://%1.domain.com/$1 [NC,L,R=301]

Also, be aware that the rule in your .htaccess file, and those I supplied, only rewrites these if the user comes in via HTTPS connections, not HTTP connections. To catch them all properly you should use:

# Rewrite www
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [NC,L,R=301]

# Rewrite other sub-domains
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteRule ^(.*)$ http://%1.domain.com/$1 [NC,L,R=301]

# Catch any https and redirect to http
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [NC,L,R=301]
 
Top Bottom