Entrance Chat Gallery Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
June 28, 2025 - @45.34 (what is this?)
Activity rating: Four Stars Posts & Arts: 63/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: :4u: ~~~~~~~~~~~  :4u: Super News: Upload a banner!

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Making an autoredirect point to the same page on diff domain


« previous next »
Pages: [1] Print
Author Topic: Making an autoredirect point to the same page on diff domain  (Read 460 times)
candycanearter07
Hero Member ⚓︎
*****


i like slimes

⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: candycanearter
Itch.io: My Games
RSS: RSS

View Profile WWWArt

Goomy, I Choose You!Suck At Something September - Did It!uh oh! a pigeon got in!Artsy Candy CaneJoined 2024!
« on: May 11, 2025 @727.53 »

Hi,

So I've been considering moving off of a neocities url and buying my own domain. The problem is that there's already a ton of links out there that point to my page.. Redirecting would obviously be the best thing, using the 404 page, but I am worried about like the path on the link being lost if i just linked directly to the domain. Is there any way to make the autoredirect point to the same path in the new domain?

ie
foo.neocities.org/about
-> example.org/about
Logged

new to oldnet be nice




Melooon
Hero Member ⚓︎
*****


So many stars!

⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

View Profile WWWArt

Ozwomp wants to know your locationHyperactive DonutGreat Posts PacmanOfficially DogThanks for being rad!a puppy for your travels
« Reply #1 on: May 11, 2025 @732.23 »

If you're planning to get Neocities supporter and add your custom domain there then you don't need to worry about this issue, Neocities will automatically redirect any old links correctly  :wizard:

However if you're switching host entirely then your best bet is to replace every page on neocities with a custom redirect page.

This is an example redirect page:
Code
<html>
    <head>
        <title>My Old page</title>
        <meta http-equiv="refresh" content="4; URL=https://mynew.url/newpage" />
        <meta property="article:modified_time" content="2025-04-11T21:34:00-0700" />
        <style>
            body {
                padding: 30px 30%;
                text-align: center;
                font-size: 2em;
            }
        </style>
    </head>
    <body>
        <p>I have moved stand by to be redirected!!</p>
    </body>
</html>

The key thing is the two meta tags in the head, the first tells the browser to refresh the tab to a new url (the content=4 value is the length of the delay in seconds before redirecting, you can make it 0 for instant redirects), and the second tells the browser to clear its cache so that the refresh 100% happens (just set it to whatever date you setup your new site) - you can also just add this meta data to your old pages head ^^
Logged


everything lost will be recovered, when you drift into the arms of the undiscovered
candycanearter07
Hero Member ⚓︎
*****


i like slimes

⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: candycanearter
Itch.io: My Games
RSS: RSS

View Profile WWWArt

Goomy, I Choose You!Suck At Something September - Did It!uh oh! a pigeon got in!Artsy Candy CaneJoined 2024!
« Reply #2 on: May 11, 2025 @769.88 »

So I'd have to manually replace all my pages?
Logged

new to oldnet be nice




nobo
Jr. Member ⚓︎
**


drainnnn

⛺︎ My Room
StatusCafe: nobo
iMood: nobo
Itch.io: My Games
RSS: RSS

View Profile WWW

First 1000 Members!Joined 2023!
« Reply #3 on: May 11, 2025 @847.52 »

You could do it with a script, although that might be advanced. It could be worth it to learn to write the script if there is enough pages, but if there's few enough pages, it might be better to do manually.
Logged

crazyroostereye
Jr. Member ⚓︎
**


I am most defiantly a Human

⛺︎ My Room
RSS: RSS

View Profile WWW

Joined 2024!
« Reply #4 on: May 13, 2025 @662.91 »

I wrote a little Python script that adds the Necessary meta tags to each Page that @Melooon mentioned in his previous Post.
 :pc:
Code
import sys, os, shutil
from bs4 import BeautifulSoup

folder = sys.argv[1]
domain = sys.argv[2]
outfolder = sys.argv[3]

for (dirpath, dirnames, filenames) in os.walk(folder):
    for i in filenames:
        new_path = dirpath.replace(folder, outfolder)
        if i.split(".")[-1] != "html":
            print(f"Copying {dirpath}/{i} to {new_path}/{i}")
            os.makedirs(f"{new_path}", exist_ok=True)
            shutil.copyfile(f"{dirpath}/{i}", f"{new_path}/{i}")
            continue
        domain_path = f"{domain}{dirpath.replace(folder, "")}/{i}"
        print(f"Processing {domain_path}")
        with open(dirpath+"/"+i, "r") as f:
            html = f.read()
        soup = BeautifulSoup(html, "html.parser")
        meta1 = soup.new_tag("meta")
        meta1["http-equiv"] = "refresh"
        meta1["content"] = f"4; URL={domain_path}"
        soup.find("head").append(meta1)

        meta2 = soup.new_tag("meta")
        meta2["property"] = "article:modified_time"
        meta2["content"] = "2025-04-11T21:34:00-0700"
        soup.find("head").append(meta2)

        os.makedirs(f"{new_path}", exist_ok=True)
        with open(f"{new_path}/{i}", "w") as f:
            f.write(str(soup))
So you have to have python3 and the bs4 module for this to work. Also I only tested it on a Linux machine. It should work on Mac but I am not sure if it works on Windows.

main.py /path/to/old/website/root https://new.domain.net /folder/to/output/fixed/site

If you need further help or the script dosen't work you are welcome to message me.  :smile:

EDIT 17:02:11 : I updated the script to copy non html files also over to the outfolder
« Last Edit: May 13, 2025 @668.69 by crazyroostereye » Logged

Pages: [1] Print 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi