Jump to content

301 redirects by PageID - missing functionality?


Recommended Posts

I've been looking at various Redirect Modules and I don't think my current requirement is possible with any of them.

I want to enter a PageID (my source page) and create a 301 redirect to a different URL (destination).

Normally you might do this in the htaccess file with page paths but I'd rather do something within PW itself.

Jumplinks comes close to supporting this but doesn't support page IDs.

The reason I need page IDs to be specified in the source and destination is that my client often updates the page path for SEO experiments etc.

If I were to use page Paths as the source and destination, they might stop working.

Link to comment
Share on other sites

It's pretty easy to implement that without a module.

Create a page reference field and add it to all applicable templates. Let's call it 'redirect_page'.

In your prepend template file, add a little snippet of code that checks if redirect_page is set and issues the redirect if it is.

<?php

if($page->redirect_page)
  $session->redirect($page->redirect_page->url);

 

  • Like 1
Link to comment
Share on other sites

Thanks BitPoet. I had that setup but wasn't sure it was using a 301 redirect method for SEO.

I also have a nice page created via ListerPro which lists all the redirects I have made. Handy for an at-a-glance view etc

Link to comment
Share on other sites

On 5/24/2023 at 11:41 AM, Peter Knight said:

The reason I need page IDs to be specified in the source and destination is that my client often updates the page path for SEO experiments etc.

If I were to use page Paths as the source and destination, they might stop working.

What about the core module Page Path History? It takes care of page URLs in case they change and redirect from old to new URLs.

ProcessWire is quite good at managing old URLs, at least for those created in your ProcessWire instance. In case of a migration it's something totally different. There is even a managing area under the settings tab in each page.

2023-05-27_21-00.thumb.png.64ba45f868541449c38b0717dfb4de82.png

There would be no real need to add redirects anymore. Unless you want to use something that never existed before.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...