注:本人使用 apache2.x + php5.2.x
项目上线,输入 domain.com 可以正常访问,但是登录却出问题了,但是在 www.domain.com 下是没问题的。这就需要我们配置一下,在输入domain.com 时自动跳到www.domain.com 。
配置如下:(1)虚拟主机 [ apache2/conf/httpd.conf ]
NameVirtualHost 223.4.x.x:80
DocumentRoot "/data/www.domain.com/public"
ServerName www.domain.com
ServerAlias http://www.domain.com/
allow from all
Options +Indexes
Options -Indexes
DirectoryIndex index.php
AllowOverride All
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
DocumentRoot "/data/www.domain.com/public"
ServerName domain.com
ServerAlias http://www.domain.com/
allow from all
Options +Indexes
Options -Indexes
DirectoryIndex index.php
AllowOverride All
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
(2)在 .htaccess 中加入
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com(.*) [NC]
RewriteBase /
RewriteRule ^(.*)(\/.*)?$ http://www.domain.com/$1$2 [R=301,L]
(3)重启apache