简体   繁体   中英

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. im trying to achieve.

if user visit newyork.example.com or ohio.example.com

both these cities point to same website means www.example.com

but display contents related to city (like OLX Done)

i have create wildcard domain *.example.com With A record i also create two subdomains

newyork.example.com and 

ohio.example.com 

also create .htaccess to redirect traffic to 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

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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