I'm trying to use nginx to redirect my main page (www.domain.com) to a subdirectory (www.domain.com/store). I have the redirect working, but whenever I use the domain name it will redirect me to the ip address (www.IP.com/store). This is my server nginx config. Thank you in advance for any help!
server {
listen 80 default_server;
server_name *.domain.com;
location / {
index index.php index.html index.htm;
}
location = / {
rewrite ^/store permanent;
}
root /usr/local/www/nginx;
}
You missed a space. rewrite ^/store permanent;
will try to match '/store' at the beginning of the uri path (thanks to the ^) and if it matches, it will rewrite it to 'permanent'. Since this is inside location = /
, it will never succeed. Instead, you need:
rewrite ^ /store permanent;