简体   繁体   English

如何对多个引用使用多个子域

[英]how to use multiple subdomain for multiple cites

i am working on a website www(dot)shopingmart(dot)com basically a classified website, i need to solve a problem im facing now i spent to much time but unable to solve. 我正在工作的网站www(dot)shopingmart(dot)com基本上是一个机密网站,我需要解决一个即时消息,现在我花了很多时间却无法解决。 im trying to achieve. 我试图实现。

if user visit newyork.example.com or ohio.example.com 如果用户访问newyork.example.com或ohio.example.com

both these cities point to same website means www.example.com 这两个城市都指向同一个网站,意味着www.example.com

but display contents related to city (like OLX Done) 但显示与城市有关的内容(例如“ OLX完成”)

i have create wildcard domain *.example.com With A record i also create two subdomains 我创建了通配符域* .example.com,并带有一条记录,我还创建了两个子域

newyork.example.com and 

ohio.example.com 

also create .htaccess to redirect traffic to index.php 还创建.htaccess将流量重定向到index.php

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

then parse 然后解析

$_SERVER['HTTP_HOST'] to obtain subdomain 

but when i type newyork.example.com it will give me 500 Internal error 但是当我键入newyork.example.com时,它将给我500内部错误

Please help and share some idea i'm unable to solve this problem 请帮助并分享一些想法,我无法解决此问题

Best Regards 最好的祝福

You should create a virtual host using a wildcard to accept all subdomains from a specific domain. 您应该使用通配符创建虚拟主机,以接受来自特定域的所有子域。

This is a config sample of a system I made that do basically what you need: 这是我制作的系统的配置样本,基本上可以满足您的需要:

NameVirtualHost *:80
<VirtualHost *:80>
     DocumentRoot /www/your_site
     ServerName example.com
     ServerAlias *.example.com
</VirtualHost>

This makes Apache to receive all subdomains (alias) for a specific domain. 这使Apache可以接收特定域的所有子域(别名)。

You should first try this approach without your rewrite rules and only insert the rules after wildcard is working. 您应该首先尝试这种方法而无需重写规则,并且仅在通配符起作用后才插入规则。

Edit: 编辑:

Regarding assets path changing under subdomains, the rewrite rule needs to point to index.php at the document root: 关于子域下资产路径的更改,重写规则需要指向文档根目录下的index.php:

RewriteRule . %{DOCUMENT_ROOT}/index.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM