【问题标题】:redirecting subdomain to main domain with htaccess使用 htaccess 将子域重定向到主域
【发布时间】:2016-04-11 08:03:35
【问题描述】:

我正在建立一个包含两个主要部分的网站,

所以我创建了两个子域:

web1.example.com web2.example.com

因为我正在使用 codeigniter 构建网站,所以我想重定向到 index.php 页面。这就是我所做的:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/web1 [R=301,NC,L]

它按预期工作,但它将 URL 更改为 example.com/web1.. 有什么办法可以保留 url web1.example.com,但仍然重定向到 example.com/web1?

我已经在使用 .htaccess 文件了:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

当我输入 web1.example.com 时,实际要执行的 url 应该是: example.com/web1,要执行的文件是 index.php ..

【问题讨论】:

  • 你期望的输出 URL 是什么

标签: php apache .htaccess codeigniter redirect


【解决方案1】:

没测试过,修改一下试试

RewriteRule ^([a-zA-Z0-9-/]+).example.com$ http://example.com/$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+).example.com/([a-zA-Z0-9-/]+) http://example.com/$1&$2 [L]

已编辑 1

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/index.php/%1&$1 [L,NC,QSA]

【讨论】:

  • 你期望的输出 URL 是什么,需要执行什么 URL
  • 我应该将 .htaccess 放在子域文件夹中,还是放在根目录中?
  • 用当前的 htaccess 文件编辑了我的问题.. 尝试将您的代码添加到其中,但没有任何反应..
  • 还提供:示例 url、预期 url、需要在该 url 上执行的文件
  • 当我进入web1.example.com时,实际执行的url应该是:example.com/web1,而要执行的文件是index.php ..这是你的意思吗?
猜你喜欢
  • 2013-06-16
  • 2014-08-19
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 2015-02-13
  • 2011-08-27
  • 1970-01-01
相关资源
最近更新 更多