Hello!
I looked at the NGINX wiki and found some examples on how to use the rewrite module for redirecting a HTTP request. I seem to have stumbled upon a problem though. The code is below.
Code:
server {
listen 80;
server_name unknown-server.com;
rewrite ^ http://www.unknown-server.com$request_uri? permanent;
access_log /srv/www/unknown-server.com/logs/access.log;
error_log /srv/www/unknown-server.com/logs/error.log;
root /srv/www/unknown-server.com/public_html;
location / {
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/img/") {
fastcgi_pass 127.0.0.1:9000;
}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/unknown-server.com/public_html$fastcgi_script_name;
}
}
When I visit
unknown-server.com it will redirect to
www.unknown-server.com (adding the 'www') which is exactly what I want; however the actual index.html file is not showing up but rather the default NGINX website that shows "Welcome to nginx!"
What I would like to have is a redirect of
http://unknown-server.com to
http://www.unknown-server.com or anything after. For example if someone visits
http://unknown-server.com/forums/path/to/something NGINX will redirect it to
http://www.unknown-server.com/forums/path/to/something - just adding the 'www' but keeping the path.
How can I do this?
Thanks in advance.
[NOTE]:
Right now the NGINX server has unknown-server.com set to accept both unknown-server.com and
www.unknown-server.com requests. I set it back until I can fix this.