Redirect old PHP pages

I have converted an older php / non template website to use pluse 5.

The old pages all ended in .php e.g. /contact-us.php and new pages using pulse 5 do not e.g now show as /contact

does anyone know of a way to setup a redirect so if old links are used it goes to the new page. I have tried adding in a 301 redirect to the htaccess file but this doesn’t seem to work.

An example of what I have tried below

Redirect 301 /contact-us.php https://www.domainname.com/contact

Thats a very good question. What is the actual file name for contact page?
A 301 redirect has to have actual filenames in the paths as far as I know.

1 Like

The original file was contact-us.php and the new page has been generated via the pulse admin and is named contact.

Old page https://www.domainname.com/contact-us.php
new page https://www.domainname.com/contact

@jdloudon is right on this

Here’s more on 301 in htaccess:

You could also do the redirecting via PHP in the file:

<?php header("Location: http://domain.tld/new/location/", true, 301); ?>

See: https://perishablepress.com/permanent-301-redirect-via-php-or-htaccess/

1 Like

Yep I did try these redirect methods in htaccess but none of these work, they just show the error 404 page. I’ve done plenty of times on non-template pulse websites but not working on this, I am guessing it is because the website won’t load a page that isn’t loaded via the admin.

E.g. if I add the old contact.php file to the root folder it just directs to error 404 page.

Did you also try the redirect in the PHP (not the htaccess)?

The htaccess shipped in Pulse 5 should allow non Pulse pages to be viewed in the root directory.

I just did a quick test.

Let us know if this is your intended behaviour :slight_smile:

After you mentioned the HTACCESS file i had a look through the one I was using and found the fault. There was a line of code for the blog written as

RewriteRule ^blog-([^-]*)$ ?page=$1&p=blog [L,QSA]

instead of

RewriteRule ^blog-page-([^-]*)$ ?page=$1&p=blog [L,QSA]

I recently download the latest pulse 5 but must have used an old / incorrect htaccess.

This appears to have solved both issue and the blog next page issue. Many thanks for all your help.

1 Like

Great thanks @Dan_p for reporting back and glad the issue has been resolved!

I had the same issue with an old Pulse 4 site and ended up redirecting the user to the new page using a PHP via a plug-in.

The code for the plug-in can be found in this GIST. Essentially the PHP looks for a super block with the old page URLs and new URLs in it and simply redirects with a 301 if a match is made. Commented out in the code is also a simple counter so you can open up the block and see how many times the redirection has happened.

To use the redirection plugin copy the redirection.php code to a new file and store it in inc/tags in your Pulse site. Create a new super block and add a new line for each redirection in the format;
old-url,new-url,1
The number at the end is just for the redirection counter.

Finally to get the redirection to work add the shortcode for the plug-in on the 404 page for the site;
{{redirection}}
Placing the code here is important as Pulse will try and locate the correct page and will automatically drop back to the 404 page before finally redirecting to the correct URL.

Redirecting URLs like this takes a little longer to set up than simply adjusting an htaccess file but it means that clients can set up unique URLs for campaigns and redirect them to standard Pulse pages without having to have me do the dirty work. :slight_smile:

2 Likes

Great solution @timplumb :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.