apache - the url that maps the second-level domain name to the first-level domain name
给我你的怀抱
给我你的怀抱 2017-05-16 17:03:56
0
4
861

Assume that the first-level domain name is taobao.com
Each store has a second-level domain name. There is a store called Baobao, and its domain name is baobao.taobao.com
Each store is accessed through the second-level domain name and redirected to taobao.com/shop/baobao

That is to say, there are a large number of stores, and each store has a second-level domain name. Assume that the domain name is xxx.taobao.com
Need to redirect to taobao.com/shop/xxx

The *A records of DNS all point to this machine.
If it is implemented using apache mod_rewrite, how to write the configuration?

Are there any other ways?

给我你的怀抱
给我你的怀抱

reply all(4)
淡淡烟草味

Nginx is probably written like this:

server {
  listen 80;
  server_name xxx.taobao.com;
  if ( $http_host ~* “^(.*)\.taobao\.com$”) {
  set $domain ;
  rewrite ^(.*) http://taobao.com/$domain/ break;
  }
}

Apache is similar to:

RewriteRule ^/([-a-z0-9]+)\.taobao\.com\/?$ http://taobao.com// [L]
迷茫

Purpose
When accessing abc.test.com jumps to www.test.com/test/abc, the browser address will display the abc.test.com address.
Method
Add a new virtual host to the apache configuration file
NameVirtualHost :80

ServerName www.test.com
ServerAlias ​​*.test.com
DocumentRoot /var/www/test
rewriteengine on
rewritecond %{HTTP_HOST} [^.]+.test.com$
rewriterule ^(.+) %{HTTP_HOST}$1 [C]
rewriterule ([^.]+).test.com(.
) /test/$1$2 #/test is the directory behind www.test.com/

Also, can you turn on your debug and look at the logs?

小葫芦

I added apache configuration:
RewriteRule ^/([-a-z0-9]+).xiaocaowangluo.com/?$ http://xiaocaowangluo.com/shop/$1/ [L]

There are two connections here http://xiaocaowangluo.com/shop/test/ http://test.xiaocaowangluo.com/ This configuration has been added.

http://test.xiaocaowangluo.com/ Still can’t jump to http://xiaocaowangluo.com/shop/test/ Do I need to add other ones?

Let me use it
RewriteEngine on RewriteCond %{HTTP_HOST} ^[^.]+.xiaocaowangluo.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+).xiaocaowangluo.com(.*) /www/xiaocaowangluo/shop/$1$2

This configuration doesn’t work either, please help me.

给我你的怀抱

apache can be written like this

RewriteRule ^/([-a-z0-9]+)\.yourdomain\.com\/?$ http://taobao.com// [L]

Appconfig:
http://www.aips.me/sae-binding-domain-subdirectory.html

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!