使用 DNS 和/或 Mod_Rewrite 进行 URL 掩码? [英] URL Masking with DNS and/or Mod_Rewrite?

查看:13
本文介绍了使用 DNS 和/或 Mod_Rewrite 进行 URL 掩码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个系统,以便像 [mydomain.com/params] 这样的多个自定义域将重定向到 [myapp.com/mydomain.com/params].我可以使用仅 DNS 设置来做到这一点吗?

我猜这是不可能的,所以将 mydomain1.com、mydomain2.com、mydomain3.com 等定向到一个 IP 地址然后使用 Mod_Rewrite 将每个请求(不可见地)定向到一个更好的解决方案myapp.com/mydomain#.com/params ?每个重定向的 URL 都指向从中央托管的 CMS 加载的内容.

任何建议、资源和/或解决方案将不胜感激!

解决方案

解决方案如下:

  1. 将所有虚域的 DNS 地址记录设置为相同的 IP 地址(例如,d1.com、d2.com、d3.com 等都将 DNS A 记录设置为一个 IP 或 FQDN)
  2. 使用 IP 作为域,使用一台 VirtualHost 设置服务器
  3. 在那个 VirtualHost 的根目录中,创建一个设置 mod_rewrite 的 .htaccess
  4. 对 .htaccess 中的 mod_rewrite 使用以下内容:

<前>选项 +FollowSymLinks重写引擎开启RewriteCond %{HTTP_HOST} (.*) [NC]重写规则 (.*) http://myapp.com/%1/$1 [P,R=301,L]

%1 = 请求的域,所以 www.d1.com 或 d1.com
$1 = 虚 URL 之后的其余 URL (d1.com/everyting/else

这个配置无形中重定向了所有请求.

示例:

<前>d1.com => 从 => myapp.com/d1.com/返回内容www.d1.com => 从 => myapp.com/www.d1.com/返回内容d1.com/blog/post/1 => 从 => myapp.com/d1.com/post/1 返回内容

I want to setup a system so that multiple custom domains like [mydomain.com/params] will redirect to [myapp.com/mydomain.com/params]. Can I do this using only DNS settings?

I'm guessing that is not possible, so would it be a better solution to direct mydomain1.com, mydomain2.com, mydomain3.com, etc. to one IP address then use Mod_Rewrite to direct each request (invisibly) to myapp.com/mydomain#.com/params ? Each redirected URL leads to content that is loaded from a centrally hosted CMS.

Any suggestions, resources, and/or solutions would be greatly appreciated!

解决方案

Here's the solution:

  1. Set DNS Address records for all vanity domains to the same IP address (so d1.com, d2.com, d3.com, etc. all have DNS A records set to one IP or FQDN for example)
  2. Setup the server with one VirtualHost using the IP as the domain
  3. Within that VirtualHost's root directory, create a .htaccess that sets up the mod_rewrite
  4. Use the following for the mod_rewrite in the .htaccess:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} (.*) [NC]
RewriteRule (.*) http://myapp.com/%1/$1 [P,R=301,L]

%1 = the domain that is requested, so www.d1.com or d1.com
$1 = the rest of the URL that comes after the vanity URL (d1.com/everyting/else

This config invisibly redirects all requests.

Examples:

d1.com => returns content from => myapp.com/d1.com/

www.d1.com => returns content from => myapp.com/www.d1.com/

d1.com/blog/post/1 => returns content from => myapp.com/d1.com/post/1

这篇关于使用 DNS 和/或 Mod_Rewrite 进行 URL 掩码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆