【问题标题】:Rewrite without changing URL in same domain using htaccess使用 htaccess 重写而不更改同一域中的 URL
【发布时间】:2016-11-12 03:55:39
【问题描述】:

我有两个网址
新网址:

http://host.ip.address/nl/business/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart

旧网址:

http://host.ip.address/nl/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart

当从浏览器请求新 URL 时,它应该从旧 URL 检索内容,并且 URL 不应在浏览器中更改。 我在 .htaccess 中尝试了以下规则,它正在重写并重定向到在我的情况下不应该这样做的旧 URL

RewriteEngine on
RewriteRule (^|.*?/)nl/business/(.*)$ /$1nl/$2 [L,R=301]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    不可能进行重定向并将原始 URL 保留在地址栏中。”这是因为根据定义,重定向涉及告诉浏览器在不同的 URL 处请求所请求的资源。因此浏览器会更新它的地址栏并使用新的 URL。

    最简单的方法是使用重写,而不是重定向。内部重写只是从与请求的本地 URL 路径不同的本地文件路径提供内容。

    你可以使用像这样简单的东西。

    RewriteEngine On
    RewriteRule nl/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart nl/business/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart
    

    您可能还需要添加

    Options +FollowSymLinks
    

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 2013-09-20
      相关资源
      最近更新 更多