XF 1.3 Force non-www redirection to www in subdomain installation

mcmedal001

Member
Hello,

I have xenforo installed on a subdomain on my website (www.ngscholars.com/comm/). I just discovered that the www version and non-www version of the site are opening separately.

From SEO point of view, I may not have ay issues because I have claimed both www and non-www version in Google Webmaster tools and set my preferred domain as the www version.

The issue I currently have now is this:

If a user logs in to the community with the www appended to the URL and later clicks on a link on the site without www, they get logged out. I have searched this forum and tried out every recommendations (editing .htaccess) made by Jake and others to no avail.

I'm here to seek help from members and support staff who have done this before.

NB: My forum is installed in a subdomain at www.ngscholars.com/comm

Thank you
 
http://xenforo.com/community/threads/frequently-asked-questions.5183/

How can I redirect all traffic to the www or non-www version of my site?
If you are on an Apache server, this can be achieved by editing the .htaccess file. Refer to the discussion thread in the forum for more information.
Note that any custom rewrite rules must come before the XenForo rewrite rules.

If you have read and followed these instructions and its still not working, you'll have to post more details about your server setup (is it Apache?), exactly what you did (including your .htaccess edits) and any other relevant details if others are to help you with this.
 
I have tried all the suggestions in this post you gave me but none worked. My server is nginx and the only modification I made is adding the code xenforo gave to enable SEF URLs. What else can I do?
 
This is what I have in my .htaccess file without the codes for redirection.

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 500 default
<IfModule mod_rewrite.c>
   RewriteEngine On
   #   If you are having problems with the rewrite rules, remove the "#" from the
   #   line that begins "RewriteBase" below. You will also have to change the path
   #   of the rewrite to reflect the path to your XenForo installation.
   #RewriteBase /xenforo
   #   This line may be needed to enable WebDAV editing with PHP as a CGI.
   #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -l [OR]
   RewriteCond %{REQUEST_FILENAME} -d
   RewriteRule ^.*$ - [NC,L]
   RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
   RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Thank you!!!
 
Thank you for your help so far. I don't have any idea of what to do next. If it should be done in the root, the it should be working as it is working for the root directory.
 
Here is what I have in the .htaccess of the WP installation:
Code:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName ngscholars.com
AuthUserFile /home/ngschola/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/ngschola/public_html/_vti_pvt/service.grp

# BEGIN WordPress
<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

Thank you
 
There's no re-write in there for non-www to www.

Is the non-www to www being done in your Web hosting control panel? Is so, you'd be better switching it off there and adding it to the .htaccess file using this:

Code:
    # Redirect non-www to www
    RewriteCond %{HTTP_HOST} ^website\.com [NC]
    RewriteRule (.*) http://www.website.com/$1 [NC,QSA,L,R=301]

using your website URL, of course.
 
I have tried all the suggestions in this post you gave me but none worked. My server is nginx and the only modification I made is adding the code xenforo gave to enable SEF URLs. What else can I do?
Is your server (actual HTTP server) nginx, or are you using it as a proxy.

Post the contents of your .htaccess file so others can see what you have done.
.htaccess doesn't come into play with nginx. The rewrites are typically done in the vhost itself or in a file that is included.
 
Thank you for this response. I'm not really sure if it is the actual http server or a proxy. I will contact my server manager for that. If it is the real server, what do I ask him to do for me? Thanks
 
Thank you for this response. I'm not really sure if it is the actual http server or a proxy. I will contact my server manager for that. If it is the real server, what do I ask him to do for me? Thanks
Main thing is whether you are running it as a proxy or not. If running it as a simple proxy for Apache, then the htaccess rewrites should work. If not using it as a proxy (but as primary content server) then the rewrites will need to be done in the vhost definition.

I use IPv6 on my sites... so this would need to be changed to reflect non-IPv6.
What this does is take all inbound requests to the www portion of the site (it has two domains pointing at it) and routes them with a 301 redirect to the non-www site.

Code:
server {
# ipv4
listen 80;
# ipv6
listen [::]:80;

    server_name www.nowservinglinux.com nowservinglinux.com www.nowservinglinux.com;
    return 301 https://servinglinux.com$request_uri;
}
 
I understand clearly now. I will inform my server manager and get back to you here. To be double sure, which redirection code should I give to him, considering that I have it installed in a sub-domain. Thank you
 
Top Bottom