HTACCESS:如何使用URL重写子子网域? [英] HTACCESS: How to URL rewrite a sub-subdomain?

查看:94
本文介绍了HTACCESS:如何使用URL重写子子网域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子域 apps.domain.com 指向 domain.com/apps

我想URL重写 appName.apps.domain.com ,其中 appName 是指向 domain.com/apps/appName

I would like to URL rewrite appName.apps.domain.com, where appName is the variable pointing to domain.com/apps/appName


  • 我正在寻找内部转发器(浏览器的URL没有更改)

  • I'm looking for an internal forward (no change in the browser's URL)

我应该拥有什么我的 .htaccess 文件,该保存在哪里?在 / apps / 文件夹中?还是在文件夹中?

What should I have in my .htaccess file and where should I save it? Within /apps/ folder? Or within the root folder?

最后,如果使用无法实现。 htaccess 文件,该怎么办?我正在使用Linux godaddy服务器作为主机。

Lastly, if it is not possible with an .htaccess file, how can I do this? I'm using a Linux godaddy server as host.

**** 问题已更新07/08 / 2018;添加了更多详细信息 ****

**** Question updated 07/08/2018; added more details ****


  • 我正在使用GoDaddy SHARED托管

  • 当前正在托管多个域

  • 因此,目录结构为 public_html / domain.com / ,其中 /domain.com / 是托管域名的名称

  • 该子子域是1个特定域专有的域

  • I am using GoDaddy SHARED hosting
  • It is currently hosting multiple domains
  • Thus, the directory structure is public_html/domain.com/, where /domain.com/ is the name of the hosted domain name(s)
  • The sub-subdomain is exclusive to 1 specific domain

示例:


  • 如果域名是 domain.com

  • 有多个名称,下面举一个例子。如果应用程序的名称是 awesome

  • 如果uri是: awesome.apps.domain.com 将指向... public_html / domain.com / apps / awesome /

  • 如果uri是: ubertz.apps.domain.com 将指向... public_html / domain.com / apps / ubertz /

  • 以此类推...

  • If the domain name is domain.com
  • There's multiple names, but to give an example. if the name of the app is awesome
  • If the uri is: awesome.apps.domain.com will point to...public_html/domain.com/apps/awesome/
  • If the uri is: ubertz.apps.domain.com will point to...public_html/domain.com/apps/ubertz/
  • And so on...

推荐答案

创建通配符子域



您需要做的第一件事是创建通配符 *。apps.domain.com 子域,子域。


  1. (如果您使用的是名称服务器,请跳过此步骤!)登录到您的域名注册商,并为 *。apps.domain.com (是的,这是一个星号)创建 A记录,并将其指向服务器IP地址。请注意,DNS最多可能需要48小时才能传播。

  1. (If you're using Nameservers, skip this step!) Log in to your domain name registrar, and create an A record for *.apps.domain.com (yeah, that's an asterisk) and point it to the server IP address. Note that DNS can take up to 48 hours to propagate.

登录您的虚拟主机帐户,然后进入菜单子域 部分下。创建一个 Subdomain *。apps.domain.com ,该文件指向 / public_html / domain.com / apps 文件夹作为其文档根。然后等待传播结束。

Log in your web hosting account and go to the menu 'Subdomains' under Domains section. Create a Subdomain *.apps.domain.com that's pointed to the "/public_html/domain.com/apps" folder as its Document Root. And wait until the propagation is over.

访问如何在cPanel中创建通配符子域如何创建子子域以获取更多信息。如果服务器的配置不允许您创建通配符子子域,则只需创建 *。domain.com 并将其指向 / public_html / domain.com / apps em>。

Visit How to create wildcard subdomain in cPanel and How to Create a Sub-Subdomain for more info. If your server's configuration didn't allow you to create a wildcard sub-subdomain then just create *.domain.com and point it to "/public_html/domain.com/apps".

将这些指令放入 .htaccess *。apps.domain.com 的文档根目录的em>文件,在这种情况下为 / public_html / domain.com / apps

Place these directives in the .htaccess file of the document root of the wildcard *.apps.domain.com which in this case is "/public_html/domain.com/apps".

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.apps\.domain\.com
RewriteRule (.*) http://domain.com/apps/%1/$1 [QSA,P,L]

%1 (。+) $ 1 (。*)。如果从特定域 http:// domain.com/apps/重写URL,则需要包含 [P] 标志%1 / $ 1 在同一服务器上,否则它将被重定向。如果要使用重写的通配符子域的查询字符串,请使用 [QSA] 标志。访问 P |代理 QSA | qsappend 以获得有关它们的更多信息。如果我忘了一些东西,只是调整一下调整,否则是服务器的错误。

The %1 is the numbered backreference of (.+) and the $1 is of (.*). You need to include the [P] flag if you URL rewrite from a specific domain http://domain.com/apps/%1/$1 in the same server, without that it will be redirected. Use the [QSA] flag if you'll going to use the query string of a rewritten wildcard subdomain. Visit P|proxy and QSA|qsappend for more info about them. And just tweak some adjustment if I forgot something, other than that, is the server's fault.

您必须为将要存在的重复子域配置 .htaccess 文件,例如 otherwildcard.apps.domain.com 另一个。 wilcard.apps.domain.com other.deep.level.apps.domain.com ,它们将复制 apps.domain.com 都具有相同的文档根目录。配置重定向或告诉客户端这些子域不存在。

You must configure your .htaccess file for the duplicate subdomains that will be going to exist, such the otherwildcard.apps.domain.com, another.wilcard.apps.domain.com and the other.deep.level.apps.domain.com that will duplicate apps.domain.com as they're all have the same document root. Configure to redirect or to tell to the client that those subdomains aren't exist.

这篇关于HTACCESS:如何使用URL重写子子网域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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