重定向来自特定域的所有请求

问题描述 投票:2回答:1

我想将来自特定域的所有请求重定向到特定目录。更确切地说,我有两个不同的域,即example.comexample.tk,两个域都指向同一台服务器。该服务器有两个不同的目录,即carsbikes。我在root上创建了.htaccess文件,但无法进行配置。我希望来自example.com的所有请求都应该重定向到cars目录。所有来自example.tk的请求都应该重定向到bikes目录。

我怎样才能成功实现这一目标?

apache .htaccess dns
1个回答
3
投票

这个.htaccess文件会将http://example.com/file.html重定向到http://example.com/cars/file.htmlhttp://example.tk/file.html重定向到http://example.tk/bikes/file.html

Filename: .htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{HTTP_HOST} !cars
RewriteRule ^(.*)$ http://example.com/cars/$1 [R=301,L]

RewriteCond %{HTTP_HOST} example.tk$ [NC]
RewriteCond %{HTTP_HOST} !bikes
RewriteRule ^(.*)$ http://example.tk/bikes/$1 [R=301,L]

我认为它会对你有所帮助

更多参考:here

© www.soinside.com 2019 - 2024. All rights reserved.