【问题标题】:Redirect to another URL without changing URL在不更改 URL 的情况下重定向到另一个 URL
【发布时间】:2016-11-17 08:15:20
【问题描述】:

我想将我的子域http://test.example.com 上的所有请求指向https://www.example.com/test-url-wordpress/,并且我写了以下.htaccess

RewriteRule ^(.*)$ https://www.example.com/test-url-wordpress/ [NC,L]

这会导致重定向到给定页面,但我不想更改 URL。我也尝试过以下解决方案,但它给了我500 Internal Server Error

重写规则 ^(.*)$ https://www.example.com/test-url-wordpress/ [P]

注意:如果有任何请求,我想显示来自给定 URL 的内容 那个子域。仅供参考,主域上的站点在 wordpress 中,这就是为什么我 不能在此处放置 ../test-url-wordpress/ 之类的相对 URL 和事件 那没用。

任何帮助将不胜感激。

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite


    【解决方案1】:

    尝试将此添加到您的 web.config 文件中 -

    <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect test.example.com to www.example.com" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="test.example.com" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/test-url-wordpress/{R:0}" />
        </rule>
      </rules>
    </rewrite>
    </system.webServer>
    

    【讨论】:

    • 好吧!你在哪里找到这个问题是针对 IIS 的。
    • 服务器是 linux 上的 apache,而不是 IIS。记住我的 URL 不应该在浏览器中改变。很高兴知道解决方案。谢谢
    猜你喜欢
    • 2018-07-30
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多