简体   繁体   中英

htaccess redirect pages to specific subdomain

Lets say I have a page at: foobar.com/application.php

I want any reference to foobar.com/application.php to redirect as www.foobar.com/application.php. I only want that rule to apply to the application.php page.

xyz.foobar.com/page1.php would not redirect. xyz.foobar.com/application.php would redirect to www.foobar.com/application.php.

(any subdomain except www).foorbar.com/application.php would redirect to 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.?

Examples for application.php page

  1. www.foobar.com/application.php would NOT redirect since it is www
  2. abc.foobar.com/application.php would redirect to www.
  3. xyz.foobar.com/application.php would redirect to www.
  4. whatever.foobar.com/application.php would redirect to www.
  5. anything.foobar.com/application.php would redirect to www.
  6. (anything here EXCEPT www) .foobar.com/application.php would redirect to 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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