Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache + PHP: how to change the value of $_SERVER['SERVER_NAME'] in apache?

Tags:

php

apache

for example, i have mysite.com and beta.mysite.com. both point to the same index file using the virtualHost directive. what will i do in the apache conf so that when i access the $_SERVER['SERVER_NAME'], the value would still be mysite.com?

this should be flexible that only the beta would be removed.

like image 873
gianebao Avatar asked Jan 20 '23 14:01

gianebao


2 Answers

Maybe you could use a ServerAlias in your VirtualHost directive, and use only one VirtualHost directive:

<VirtualHost *:80>
  ServerName mysite.com
  ServerAlias beta.mysite.com
  ...
</VirtualHost>
like image 65
bbg Avatar answered Jan 23 '23 07:01

bbg


http://httpd.apache.org/docs/2.2/mod/core.html#usecanonicalname

Try this:

<VirtualHost *:80>
  ServerName mysite.com
  ServerAlias beta.mysite.com

  UseCanonicalName On
</VirtualHost>

I'm assuming you have 1 VH, and not: 1 for each site (since they are the same site).

Restart apache after.

like image 36
rightstuff Avatar answered Jan 23 '23 08:01

rightstuff