NginX rewrite/redirect rule http://www to http:// -


i need basic redirect rule if types: www.site.com redirected site.com. need neat , clean in browser.

i tried in nginx serverblock:

# trying redirects http://   www.site.com http://   site.com if ($host = "www.site.com") { rewrite ^ $scheme://site.com$uri permanent; }  ...  location / {     try_files $uri $uri/ @modx-rewrite /index.php?/$request_uri;     location ~ .php$ {     fastcgi_pass unix:/var/run/php5-fpm.sock;     fastcgi_index index.php;     fastcgi_param script_filename $document_root$fastcgi_script_name;     include fastcgi_params;     } 

but reason didn't work , "server not found error". , adds http s in address.

without rules site opens fine , runs on https , pages open https: // site.com links.

thanks.

nb: intentionally added several spaces in code snipets in address, otherwise stackoverflow won't let me post it.

make simpler:

server {     listen       80;     server_name  example.com;     location / { .........; } } server {     listen       80;     server_name  www.example.com;     location / { return 301 http://example.com$request_uri; } } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -