簡體   English   中英

永久重定向301,帶有/?lang = de

[英]Permanent redirect 301 with /?lang=de

我需要將多語言網站重定向到新域,並將使用.htaccess文件。 我將所有舊頁面重定向到新域上各自的新頁面。

舊網址

Englisch
    Main page: www.olddomain.com
    Sub pages: www.olddomain.com/bike-rental

Spanish
    Main: www.olddomain.com/?lang=es
    Sub pages: www.olddomain.com/bike-rental?lang=es

German
    Main: www.olddomain.com/?lang=de
    Sub pages: www.olddomain.com/bike-rental?lang=de

新網址

Englisch
    Main page: www.new-domain.com
    Sub pages: www.new-domain.com/bike-rental

Spanish
    Main: www.new-domain.com/es
    Sub pages: www.new-domain.com/es/alquiler-de-bicis
German
    Main: www.new-domain.com/de
    Sub pages: www.new-domain.com/de/fahrradvermietung

我意識到它不適用於.htaac​​ces文件中的正常重定向,例如:

    Redirect 301 /?lang=de http://www.new-domain.com/de/
    Redirect 301 /bike-rental?lang=de http://www.new-domain.com/de/fahrradvermietung

有什么主意如何將那些舊的URL重定向到新的URL?

謝謝

自php 5.3.0起添加此變量:

$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale; // returns "en_US"
$localeshort = substr($locale, -2);
echo $localeshort; // returns "US"

如果使用此選項,則可以使用以下內容進行重定向:

Header("Location: index.php?lang=".$localeshort);

或使用: 此工具可創建重定向,重復此操作直到您擁有所有語言。 圖片

看到我以前的消息:由於PHP此功能已添加:

$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale; // returns "en_US"
$localeshort = substr($locale, -2);
echo $localeshort; // returns "US"

在您的.htacces中使用

RewriteEngine on

RewriteRule ^(.*)$ /index.php [R=permanent,L]

現在,它將在開始時重定向到頁面。 這是我知道的唯一解決方案。

您可以在htaccess中執行以下操作:

RewriteCond %{REQUEST_URI} !^/bike-rental$
RewriteCond %{QUERY_STRING} ^lang=(.*)$ 
RewriteRule ^(.*)/ /bike-rental?lang=%1 [L,R=301]

(經過測試並添加了條件,以避免循環重寫)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM