【问题标题】:Redirect subdomain to index .php将子域重定向到索引 .php
【发布时间】:2015-08-04 15:40:06
【问题描述】:

我想将我的子域重定向到它的索引文件,将主域重定向到它自己的索引文件。

例子

对于 www.example.com -> index.html

subdomain.example.com - >index.php

我对主域有以下规则

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

www.example.com 根文件夹是 public/

同时

subdomain.example.com 根文件夹是 public/folder/

主域重定向正在运行。但是如何将 subdomain.example.com 重定向到它的 index.php 即到 public/folder/index.php ?应该有单独的 .htaccess 文件还是公共文件?

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    您可以在 public/.htaccess 中使用:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
    RewriteCond %{REQUEST_URI} !^/folder/ [NC]
    RewriteRule ^ folder%{REQUEST_URI} [NE,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [L]
    

    在文件夹/.htaccess中

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    【讨论】:

      猜你喜欢
      • 2017-07-10
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 2012-07-22
      • 2021-05-29
      • 2011-08-27
      相关资源
      最近更新 更多