产品服务AMH 免费服务器主机面板SSL证书 免费SSL证书申请 担保单 免费安全、零费率交易平台编程助手免费智能写代码、翻译AMYSQL 免费MySQL管理工具

AMH 社区首页

 AMH社区 - 开放自由有价值的社区

[求助帖] 如何将不带www的网址全部301跳转?

joosan
铝牌会员
398.25 价值分

joosan 发表于 2015-03-02 12:00:48
本帖最后由 joosan 于 2015-3-2 13:31 编辑

请问高手,如何将我的网站不带www的,如aaa.com跳转到www.aaa.com;aaa.com/hitml全部跳转到www.aaa.com/hitml

在哪里改
这里?/usr/local/nginx/conf/nginx.conf

还是这里?/usr/local/nginx/conf/vhost/
2015-03-02 12:00:48 1

cs123456
银牌会员
1463.00 价值分

在vhost里面的配置上修改

或者你条用个伪静态的规则,在规则内修改。
  支持 (0分)  反对 (0分)
回复  2015-03-02 16:04:45 2

cs123456
银牌会员
1463.00 价值分

if ($host = 'xxx.com' ) {
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
}
  支持 (0分)  反对 (0分)
回复  2015-03-02 16:05:35 3

joosan
铝牌会员
398.25 价值分

本帖最后由 joosan 于 2015-3-2 17:25 编辑

引用:
cs123456 发表于 2015-3-2 16:04
在vhost里面的配置上修改

或者你条用个伪静态的规则,在规则内修改。

终于有人回复了,先谢谢!

以下是dz的伪静态,应该怎么改?加在那个位置?在vhost里面我也不知道加在那个位置?有劳了!

location / {
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
return 404;
}
}
  支持 (0分)  反对 (0分)
回复  2015-03-02 17:24:18 4

cs123456
银牌会员
1463.00 价值分

放到主机conf文件里面
比如xxx.conf
  支持 (0分)  反对 (0分)
回复  2015-03-02 17:57:19 5

joosan
铝牌会员
398.25 价值分

引用:
cs123456 发表于 2015-3-2 17:57
放到主机conf文件里面
比如xxx.conf


具体插入到那个地方?
server
{
listen 80;
server_name baidu.com www.baidu.com; #server_name end
index index.html index.htm index.php; #index end

set $subdomain '';
root /home/wwwroot/baidu/web$subdomain;
include rewrite/discuz.conf; #rewrite end

#error_page
location ~ /ErrorPages/(400|401|403|404|405|502|503)\.html$
{
root /home/wwwroot/baidu/web;
}


location ~ .*\.php$
{
fastcgi_pass unix:/tmp/php-cgi-baidu.sock;
fastcgi_index index.php;
include fcgi-host.conf;
fastcgi_param DOCUMENT_ROOT /home/wwwroot/baidu/web$subdomain;
fastcgi_param SCRIPT_FILENAME /home/wwwroot/baidu/web$subdomain$fastcgi_script_name;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
{
expires 30d;
}

location ~ .*\.(js|css)$
{
expires 12h;
}

access_log off; #access_log end
error_log /dev/null; #error_log end
}
  支持 (0分)  反对 (0分)
回复  2015-03-02 18:57:57 6

amysql
创始人
99530.81 价值分

引用:
joosan 发表于 2015-3-2 17:24
终于有人回复了,先谢谢!

以下是dz的伪静态,应该怎么改?加在那个位置?在vhost里面我也不知道加在那个 ...


加在你已经有的规则上面就行了。
  支持 (0分)  反对 (0分)
回复  2015-03-03 14:38:42 7

AMH面板 - 好用高效低占用、安全可靠极稳定

joosan
铝牌会员
398.25 价值分

引用:
amysql 发表于 2015-3-3 14:38
加在你已经有的规则上面就行了。


老大 插入到伪静态规则前面出错了
[警告] Nginx配置Rewrite规则错误,请查检改正。 [AMRewrite-1.0 admin] [OK] AMRewrite-1.0 is already installed. nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /usr/local/nginx/conf/nginx.conf:84 nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
  支持 (0分)  反对 (0分)
回复  2015-03-04 09:00:27 8
 1  (总1页)
AMH社区列表
用户服务中心