使www.example.com和example.com使用相同的会话变量的最佳方式? [英] Best way to make www.example.com AND example.com use the same session variables?
问题描述
我的工作网页(姑且称之为example.com),并添加下CNAME(别名)的DNS记录:
主机记录指向TTL
WWW example.com 14400
然而,当我通过example.com导航,被设置不会保留,如果我去www.example.com
会话变量什么是使www.example.com和example.com使用相同的会话变量的最佳方式?
我在使用Ubuntu 12.04,PHP5,Apache2的。
<虚拟主机*:80>
站长的ServerAdmin @本地
服务器名www.example.com
重定向301 / http://example.com/
DocumentRoot的/无功/网络/的public_html
<目录/>
有FollowSymLinks
设置AllowOverride无
< /目录>
<目录/ var /网络/的public_html>
选择指数多视图了FollowSymLinks
设置AllowOverride无
为了允许,拒绝
所有允许
< /目录> ScriptAlias指令/的cgi-bin / / usr / lib目录/ cgi-bin目录/
<目录/ usr / lib目录/ cgi-bin目录>
设置AllowOverride无
选项+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
为了允许,拒绝
所有允许
< /目录> 错误日志/var/log/apache2/error.log #可能的值包括:调试,信息,通知,警告,错误,暴击,
#警报,EMERG。
LOGLEVEL警告 的CustomLog /var/log/apache2/access.log结合别名/ DOC /的/ usr /共享/ DOC /
<目录的/ usr /共享/ DOC />
选择多视图索引了FollowSymLinks
设置AllowOverride无
为了否认,允许
所有拒绝
从127.0.0.0/255.0.0.0允许:: 1/128
< /目录>
什么是做,www.mysite.com和mysite.com使用相同的会话变量的最佳方式?
块引用>,最好的方法是不可兼得主机名运行相同的位点。
选择其中之一是规范的,那么一切都从另一个重定向到规范之一。
<虚拟主机*:80>
服务器名称example.com
重定向301 / http://www.example.com
等等I'm working on a webpage (let's call it example.com) and added the DNS record under CNAME (Alias):
Host Record Points to TTL www example.com 14400
However when I navigate through example.com, the session variables that are set are not retained if I go to www.example.com
What is the best way to make www.example.com AND example.com use the same session variables?
I'm using ubuntu 12.04, php5, apache2.
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName www.example.com Redirect 301 / http://example.com/ DocumentRoot /var/www/public_html <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/public_html> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory>
解决方案What is the best way to make www.mysite.com AND mysite.com use the same session variables?
The best way is to not have both host names running the same site.
Pick one of them to be canonical, then redirect everything from the other to the canonical one.
<VirtualHost *:80> ServerName example.com Redirect 301 / http://www.example.com etc
这篇关于使www.example.com和example.com使用相同的会话变量的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!