简体   繁体   English

htaccess 将页面重定向到特定的子域

[英]htaccess redirect pages to specific subdomain

Lets say I have a page at: foobar.com/application.php假设我有一个页面: foob​​ar.com/application.php

I want any reference to foobar.com/application.php to redirect as www.foobar.com/application.php.我希望对 foobar.com/application.php 的任何引用都重定向为 www.foobar.com/application.php。 I only want that rule to apply to the application.php page.我只希望该规则适用于 application.php 页面。

xyz.foobar.com/page1.php would not redirect. xyz.foobar.com/page1.php 不会重定向。 xyz.foobar.com/application.php would redirect to www.foobar.com/application.php. xyz.foobar.com/application.php 将重定向到 www.foobar.com/application.php。

(any subdomain except www).foorbar.com/application.php would redirect to www. (除 www 之外的任何子域)。foobar.com/application.php 将重定向到 www。

How can I form a htaccess rule that says when the application.php page is accessed to check the subdomain and if it's not www., then make it www.?我如何形成一个 htaccess 规则,说明何时访问 application.php 页面以检查子域,如果它不是 www.,则将其设为 www.?

Examples for application.php page application.php 页面示例

  1. www.foobar.com/application.php would NOT redirect since it is www www.foobar.com/application.php不会重定向,因为它是 www
  2. abc.foobar.com/application.php would redirect to www. abc.foobar.com/application.php将重定向到 www。
  3. xyz.foobar.com/application.php would redirect to www. xyz.foobar.com/application.php将重定向到 www。
  4. whatever.foobar.com/application.php would redirect to www. what.foobar.com/application.php将重定向到 www。
  5. anything.foobar.com/application.php would redirect to www. any.foobar.com/application.php将重定向到 www。
  6. (anything here EXCEPT www) .foobar.com/application.php would redirect to www. (这里除了 www之外的任何内容) .foobar.com/application.php将重定向到 www。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xyz.foobar.com$ [NC]
RewriteCond %{THE_REQUEST} /application\.php [NC]
RewriteRule ^(.*)$ http://www.foobar.com/$1 [NC,R,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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