【问题标题】:.htaccess redirect main domain and not subdomain.htaccess 重定向主域而不是子域
【发布时间】:2015-04-09 10:55:33
【问题描述】:

我有域 mydomain.co 和 mydomain.com 在 mydomain.co 中,我想安装 YOURLS。

效果很好,但我想创建这样的重定向。

example.org -> R301 -> example.com

example.org/* -> /yourls-loader.php

我有这样的东西,但它不起作用:(

<IfModule mod_rewrite.c>                                                                                                                                                                                           
RewriteEngine On                                                                                                                                                                                                   
RewriteCond %{HTTP_HOST} ^(www.)?example.org                                                                                                                                                                          
RewriteRule ^$ http://example.com [L,R=301]                                                                                                                                                                     
#RewriteBase /                                                                                                                                                                                                     
RewriteCond %{REQUEST_FILENAME} !-f                                                                                                                                                                                
RewriteCond %{REQUEST_FILENAME} !-d                                                                                                                                                                                
RewriteRule ^.*$ /yourls-loader.php [L]                                                                                                                                                                            
</IfModule>

.htaccess 文件应该如何查找我的配置?

【问题讨论】:

  • 您能接受您的回答吗?这样,您的问题就不会再显示为 unanswered。谢谢!
  • 是的,我认为我不应该接受自己的答案,但我想为其他人发布正确的答案。

标签: apache .htaccess mod-rewrite redirect


【解决方案1】:

终于,我搞定了。

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^(www.)?example.org [NC]
  RewriteCond %{REQUEST_URI} ^/(.+)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteRule ^(.*)$ /yourls-loader.php [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteRule ^(.*)$ http://example.com [R=301,L]
</IfModule>

【讨论】:

    【解决方案2】:

    你可以简单地使用:

    RewriteCond %{HTTP_HOST} !^example\.org$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    

    所有有子域的东西都会被重定向到没有子域的。其余的保持不变。

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 2014-09-23
      • 2014-01-07
      • 2014-02-28
      • 2013-05-28
      相关资源
      最近更新 更多