【问题标题】:htaccess redirect - subdomain with query ignored - subdomain only redirect to phphtaccess 重定向 - 忽略查询的子域 - 子域仅重定向到 php
【发布时间】:2014-06-22 14:38:50
【问题描述】:

我想允许忽略包含查询或请求的超域:

例如 http://sub.domain.com/documentshttp://sub.domain.com/index.php?user=fred

但如果 URI 仅指向子域

例如 http://sub.domain.com

如果被重定向到

http://sub.domain.com/portal.php

如何使用 htaccess 文件来做到这一点?

【问题讨论】:

  • 到目前为止你尝试过什么? How to ask a question
  • RewriteCond %{HTTP_URI} !^www.domain.com$ [NC]

标签: php .htaccess mod-rewrite redirect


【解决方案1】:

将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^/?$ /portal.php [L]

【讨论】:

  • 谢谢你让这个工作 - RewriteCond %{HTTP_HOST} !domain.com$ [NC]
  • 如果您想为sub.domain 使用此规则,那么当您拥有多个子域时,使用RewriteCond %{HTTP_HOST} !domain.com$ [NC] 并不总是有效。使用RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC] 更准确
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-06
  • 2012-03-09
  • 1970-01-01
  • 2011-04-29
  • 2010-11-22
  • 2011-08-27
相关资源
最近更新 更多