OpenShift的.htaccess重写规则不起作用 [英] OpenShift .htaccess RewriteRule doesn't work

查看:162
本文介绍了OpenShift的.htaccess重写规则不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用的子域多用户文字preSS安装。我想将其迁移到使用的子文件夹多用户。我已经设置了子多用户和它的实际工作。现在,我想从旧地址重定向到新的地址。例如:

I have a multiuser wordpress install which is currently using subdomains. I'd like to migrate it to use subfolder multiuser. I've set up subfolder multi-user and it actually works. Now, I'd like to redirect from the old address to the new address. For instance:

peter.example.com - > example.com/peter

peter.example.com -> example.com/peter

两个域以上被适当添加为OpenShift别名。为了使重定向,我创建的.htaccess文件重写规则。它看起来是这样的:

Both domains above are properly added as aliases in OpenShift. To cause the redirect, I created a rewrite rule in the .htaccess file. It looks like this:

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

这会导致一个重定向循环。检查这一点,peter.example.com一个简单的要求生产:

This results in a redirect loop. Inspecting this, a simple request on peter.example.com produces:

HTTP/1.1 301 Moved Permanently
Date: Mon, 05 Jan 2015 03:30:58 GMT
Server: Apache/2.2.15 (Red Hat)
Location: http://peter.example.com/peter/
Content-Length: 335
Content-Type: text/html; charset=iso-8859-1
Accept-Ranges: none

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://example.com/peter/">here</a>.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at peter.example.com Port 80</address>
</body></html>

返回值是正确的,是身体的URL;所以我知道我的重写规则正在评估。然而,在Location头的URL不正确。为什么?在我看来,如果OpenShift是重整这个头导致重定向失败。

The return value is correct, as is the URL in the body; so I know my RewriteRule is being evaluated. However, the URL in the Location header is incorrect. Why? It seems to me as if OpenShift is mangling this header causing the redirect to fail.

这是在OpenShift一个错误?在我的重写规则?有没有人有一个建议的解决方法吗?

Is this a bug in OpenShift? In my RewriteRule? Does anyone have a suggested workaround?

推荐答案

我遇到了同样的问题,并且能证明OpenShift重写Location头。下面是我做了,结果发现:

I've encountered the same issue, and were able to prove that OpenShift rewrites the location header. Here's what I did and found:

  1. 设置了一个应用程序时的 test-app.rhcloud.com
  2. 分配了一个自定义域的 test.com
  3. 创建发出以下HTTP头一个非常简单的PHP页面

  1. Set up an app at test-app.rhcloud.com
  2. Assigned a custom domain test.com
  3. Created a very simple PHP page that issued the following HTTP header

Location: http://www.example.com/

  • 当我打开网页,发送下面的头:

  • When I open that page, it sends the following header:

    Location: http://test-app.rhcloud.com/
    

  • 如果我重定向更改为任何其他领域(如www.example2.com),它的工作原理(不重写重定向)。

  • If I change the redirect to any other domain (e.g. www.example2.com), it works (doesn't rewrite redirect).

    我还没有找到一个解释,但其他似乎有这个问题了。我不知道一个合适的解决办法要么,但你可以尝试使用HTML重定向(meta标签)。谷歌已经的这类重定向的支持有限。

    I haven't yet found an explanation, but others seem to be having problems with this too. I don't know of a proper workaround either, but you could try using HTML redirects (with meta tags). Google has limited support for this kind of redirection.

    更新:我已经找到了解决办法。简单地追加在URL后的默认端口号(80)和OpenShift不会重写你的URL。因为,端口号是默认情况下,浏览器会删除它,你的用户甚至不会看到任何东西。

    UPDATE: I've found a solution. Simply append the default port number (80) after the URL, and OpenShift won't rewrite your URL. Because, the port number is the default, the browsers will remove it, and your users won't even see anything.

    这是怎么更新的重写规则将如下所示:

    This is how your updated rewrite rule would look like:

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

    这篇关于OpenShift的.htaccess重写规则不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆