【问题标题】:.htaccess rewrite and subdomains.htaccess 重写和子域
【发布时间】:2010-12-29 04:38:04
【问题描述】:

我有一个子域设置为 onlinedev.domain.com 我需要使用 htaccess 重写到 domain.com/online_content,同时仍然在地址栏中显示 onlinedev.domain.com(SSL 用于 onlinedev.domain.com)。 这是我目前非常接近的:

php_flag display_errors off

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} onlinedev\.domain\.com$ [NC] 
RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC] 
RewriteCond %2<->%3 !^(.*)<->\1$ [NC] 
RewriteRule ^(.+) /%2/$1 [L]

这会正确地重写为 domain.com/onlinedev,但如果我尝试将 RewriteRule 更改为:

RewriteRule ^(.+) /online_content/$1 [L]

我收到一个错误

我知道通常有更好的方法来完成这个子域的工作,但是在没有进入服务器配置和 DNS 详细信息的情况下,我需要使用 htaccess 来完成。

是的,我确实需要重写到与子域名称不同的目录。

【问题讨论】:

  • 您面临哪个错误?服务器是否启动但没有正确定向或者这是一个配置错误?干杯,CaioToOn!
  • 我收到以下错误:内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。谢谢,乔什
  • 所以请尝试重新启动服务器。然后查看 apache/logs/error.log 文件。查看文件末尾并发布您遇到的错误。
  • 这是错误:[Tue Dec 22 10:15:01 2009] [error] [client xxx.xxx.xxx.xxx] 由于可能的配置错误,请求超出了 10 个内部重定向的限制.如有必要,使用“LimitInternalRecursion”增加限制。使用'LogLevel debug'来获取回溯。,referer:onlinedev.domain.com 所以,看起来它正在重定向到很多......也许我需要检查以确保重写尚未发生?我不确定我会怎么做。谢谢。

标签: apache .htaccess mod-rewrite


【解决方案1】:

试试这个规则:

RewriteCond %{HTTP_HOST} =onlinedev.example.com [NC]
RewriteCond $0 !^online_content/
RewriteRule .+ /online_content/$0 [L]

【讨论】:

    【解决方案2】:

    好吧,我想通了。 问题是我造成了无限循环。 重写发生后,它仍在尝试重写目录。 这是我处理它的新 htaccess:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^$ 
    RewriteCond %{HTTP_HOST} onlinedev\\.domain\\.com$ [NC] 
    RewriteCond %{REQUEST_URI} !^/online_content/
    RewriteRule ^(.+) /online_content/$1 [L]
    

    请注意,我添加了一项检查以确保 REQUEST_URI 不是我要重写的目录的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-15
      • 2011-02-04
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多