簡體   English   中英

htaccess重定向-鏈接結構稍有更改的舊域到新域

[英]htaccess Redirect - Old Domain to New Domain with Slight Change in link structure

我被卡住了。 我對htaccess不太了解,只是介紹一下。 有人可以看一下代碼,然后告訴我它怎么了。 我只想將一個舊站點重定向到一個新站點,唯一的變化就是域,一個將在舊/新頁面之間匹配的變量以及為永久鏈接結構添加的單詞。

到目前為止,我嘗試了一些變體:

Options +FolowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-$1-matchingword2-differentword-matchingword3/ [R=301,L]

Options +FolowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-%1-matchingword2-differentword-matchingword3/ [R=301,L]

RewriteCond %{QUERY_STRING}  ^$
RewriteRule ^domain\.com/matchingword1-(.*)-matchingword2-matchingword3/$ http://www.newdomain.com/matchingword1-\$1-matchingword2-differentword-matchingword3/\ [R=301? [R=301,NE,NC]

(。*)部分與新域上的$ 1完全相同,但是永久鏈接略有不同。 固定鏈接的部分(。*)將是多個單詞和數字中的任何內容。

例如:matchingword1-this-page-is-1st-matchingword2-matchingword3 /重定向到newdomain點com / matchingword1-this-page-is-1st-matchingword2-differentword-matchingword3 /

HTTP_HOST的重寫條件是在請求的“ Host:”標頭中傳遞的條件,該標頭僅包含主機(在某些情況下為端口)。 請求URI不是HTTP_HOST一部分。 嘗試這樣的事情:

RewriteCond %{HTTP_HOST} ^.*domain.com [NC]
RewriteRule ^matchingword1-(.*)-matchingword2-matchingword3/ http://www.newdomain.com/matchingword1-$1-matchingword2-differentword-matchingword3/ [R=301,L]

最后一組看起來根本不起作用。

編輯:注釋不會讓我插入代碼

如果要重定向所有內容,則應使用mod_alias的RedirectMatch:

RedirectMatch ^(.*)$ http://www.newdomain.com/$1

如果要在apache的同一實例上提供目錄(例如,domain.com和newdomain.com實際上是從同一目錄提供服務的同一服務器),則需要重寫。 像這樣:

RewriteCond %{HTTP_HOST} ^.*domain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

暫無
暫無

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

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