Welcome! Log In Create A New Profile

Advanced

Redirect non-www, www to same page

Posted by poly1 
Redirect non-www, www to same page
June 04, 2011 06:29PM
I have a vbulletin forum registered with the following domain:

http://studioleaks.info


However the actual forum itself is located in a folder called "forums", under the "public" directory. The only content that's in my site root is an under construction page, which I don't want visitors to see unless the site's under construction, so I need to make sure that all traffic redirects to:

www.studioleaks.info/forums/

Until recently I was using Apache/Cpanel, with the following rule placed in an .htaccess file in my forum root:

RewriteCond %{HTTP_HOST} !^www\.studioleaks\.info
RewriteRule (.*) http://www.studioleaks.info/forums/$1 [R=301,L]

This rewrote the non-www url to the www version (I've set www as my preferred domain in Google Webmaster Tools). Regardless of whether a visitor typed in the www or non-www version of studioleaks.info, they would be redirected to:

http://www.studioleaks.info/forums/

Since switching to nginx, I've attempted to write a similar rule to do this, but with limited success. If I type in the non-www version of studioleaks.info, it redirects properly, however if I type in the www version (i.e. www.studioleaks.info) it still goes to the under construction page in my site root). How do I fix this?

Here is my current config file (some info changed for privacy reasons):

server {
listen 80;
server_name site.studioleaks.info;
root html;

location / {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen server-ip-address:80;
server_name studioleaks.info;
rewrite ^ http://www.studioleaks.info/forums$request_uri? permanent;
}

server {
listen server-ip-address:80;
server_name www.studioleaks.info;
access_log /.../.../.../.../log/access.log;
error_log /.../.../.../.../log/error.log;
root /.../.../.../.../public;
index index.html index.php;

site.studioleaks.info is my server name, set in /etc/hosts, and also my FQDN. As I understand it, this is a preferable arrangement to using a non-FQDN domain?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 216
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready