Is this possible to always redirect
from
www.name.blogspot.com/title
to
www.name.blogspot.com/p/title.html
For example, when someone type www.name.blogspot.com/title
so it is automatically redirect to www.name.blogspot.com/p/title.html
maybe need some javascript that always auto-generate to convert incoming url to the correct url.
usually, I used this script below, but it still manually method, so edited one by one if there is many links.
<script>
if(window.location.href == 'https://www.name.blosgpot.com/title')
{
window.location="https://www.name.blosgpot.com/p/title.html";
}
</script>
Thankyou for your help
Idealy you want to do this in the server, for example, if you are using Nginx, you can rewrite incomming requests with a given pattern URL to another path:
server{
...
location /title {
rewrite ^/(.*)$ https://www.newsite.com/p/$1 redirect;
}
...
}
But if you need to do it on the client, you can use a similar logic, matching patterns and "rewriting" the URL, something like this:
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.