【问题标题】:.htaccess - Redirect domain2.com to domain1.com/folder without changing the url.htaccess - 将 domain2.com 重定向到 domain1.com/folder 而不更改 url
【发布时间】:2017-03-21 19:33:02
【问题描述】:

我有两个域名。假设 domain1.com 和 domain2.com。
我的主网站在 domain1.com 上运行。
我想在 domain1.com/blog 上运行一个博客,但我想使用 domain2.com 作为这个博客的 url。

我目前在我的.htaccess 文件中有这个:

RewriteCond %{HTTP_HOST} ^domain2.com
RewriteRule ^(.*) http://domain1.com/blog [P]

这可行,但是当我输入 domain2.com 时,url 更改为 domain2.com/blog,我只想要没有 /blog 的 domain2.com。

我已经搜索了一个多小时,但找不到合适的解决方案。

有什么想法吗?

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    试试这个:

    RewriteCond %{HTTP_HOST} domain2.com
    RewriteRule ^(.*)$ http://domain1.com/blog/$1 [L]
    

    【讨论】:

      【解决方案2】:

      尝试在您的根目录中使用它.htaccess

      RewriteEngine On
      RewriteRule ^$ blog/
      RewriteCond %{REQUEST_FILENAME} !-f 
      RewriteCond %{REQUEST_FILENAME} !-d 
      RewriteRule ^(.*)$ blog/$1
      

      这将采用domain2.com/blog 并使生成的网址显示domain2.com,但仍会加载/blog 文件夹中的内容。

      确保在测试之前清除缓存。

      【讨论】:

        猜你喜欢
        • 2013-06-13
        • 2019-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-21
        • 2020-07-23
        • 2019-03-05
        相关资源
        最近更新 更多