how to convert www.example.com/posts/123 to example.com/posts/123?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 04:01:38

问题


I am using nginx 1.2.1 running in Ubuntu 12.10

I have followed the solution in https://stackoverflow.com/a/7958540/80353

So my vhosts now look like:

server {
        listen 80;
        server_name www.example.com;
        return 301 http://example.com$request_uri;
}
server {
        listen 80;
        client_max_body_size 5M;
        server_name example.com;
        root /var/virtual/example.com/webroot;
        include common.conf;
        include php.conf;
}

Not sure what I did wrong.

Currently, whenever I do a www.example.com/posts/123, I get 302 to example.com

I was expecting example.com/posts/123

UPDATE:

server {
        listen 80;
        server_name www.example.com;
        rewrite ^(.*) http://example.com$1 permanent;
}
server {
        listen 80;
        client_max_body_size 5M;
        server_name example.com;
        root /var/virtual/example.com/webroot;
        include common.conf;
        include php.conf;
}

common.conf is:

index index.html;

location ~ /\.ht {
        deny all;
}

cakephp.conf is:

include php.conf;

location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        expires max;
        access_log off;
}

php.conf is:

location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
}

index index.php;

来源:https://stackoverflow.com/questions/22093091/how-to-convert-www-example-com-posts-123-to-example-com-posts-123

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!