簡體   English   中英

博客點重定向

[英]Blogspot Redirect

這是否可以始終重定向

www.name.blogspot.com/title

www.name.blogspot.com/p/title.html

例如,當有人鍵入www.name.blogspot.com/title

所以它會自動重定向到www.name.blogspot.com/p/title.html

可能需要一些始終自動生成的 javascript 以將傳入的 url 轉換為正確的 url。

通常我在下面使用這個腳本,但它仍然是手動方法,所以如果有很多鏈接,請一一編輯。

<script>
if(window.location.href == &#39;https://www.name.blosgpot.com/title&#39;)
{
window.location=&quot;https://www.name.blosgpot.com/p/title.html&quot;;
}
</script>

謝謝您的幫助

理想情況下,您希望在服務器中執行此操作,例如,如果您使用 Nginx,您可以使用給定模式 URL 將傳入請求重寫到另一個路徑:

server{
...
    location /title {
        rewrite ^/(.*)$ https://www.newsite.com/p/$1 redirect;
    }
...
}

但如果您需要在客戶端執行此操作,您可以使用類似的邏輯、匹配模式並“重寫”URL,如下所示:

const myPattern = /https:\/\/name.blosgpot.com(.*)/
const path = window.location.href.match(myPattern)[1]
if (path) {
  window.location.href = "https://www.name.blosgpot.com/p" + path
}

暫無
暫無

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

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