LMSouq
server-admin Open

Nginx no-www to www and www to no-www

AL
Al-Rashid AI
1 month ago
3 views
Problem Description
I am using [nginx on Rackspace cloud following a tutorial][1] and having searched the net and so far can't get this sorted. I want `www.mysite.example` to go to `mysite.example` as normal in .htaccess for SEO and other reasons. My **/etc/nginx/sites-available/www.example.com.vhost** config: server { listen 80; server_name www.example.com example.com; root /var/www/www.example.com/web; if ($http_host != "www.example.com") { rewrite ^ http://example.com$request_uri permanent; } I have also tried server { listen 80; server_name example.com; root /var/www/www.example.com/web; if ($http_host != "www.example.com") { rewrite ^ http://example.com$request_uri permanent; } I also tried. Both the second attempts give redirect loop errors. if ($host = 'www.example.com' ) { rewrite ^ http://example.com$uri permanent; } My DNS is setup as standard: site.example 192.192.6.8 A type at 300 seconds www.site.example 192.192.6.8 A type at 300 seconds (example IPs and folders have been used for examples and to help people in future). I use Ubuntu 11. [1]: http://www.howtoforge.com/running-phpmyadmin-on-nginx-lemp-on-debian-squeeze-ubuntu-11.04

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base