404 Redirect

Permalink
It's awesome that we can customize the 404 page people get for dead links etc... But is it possible to get the page to automatically redirect visitors somewhere?

i.e.

I recently launched a site, Google had extensively linked to a number of static html pages that no longer exist.

Rather than a 404, I would like to still capitalize on that traffic, and redirect users to the websites homepage.

Any ideas?

myFullFlavour
 
Mnkras replied on at Permalink Reply
Mnkras
you can toatally customize it as it is a single page called not_found i believe
myFullFlavour replied on at Permalink Reply
myFullFlavour
Expand? Instructions...?
Mnkras replied on at Permalink Reply
Mnkras
by default this is in the file:

<? defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<h1 class="error"><?=t('Page Not Found')?></h1>
<?=t('No page could be found at this address.')?>
<? if (is_object($c)) { ?>
   <br/><br/>
   <? $a = new Area("Main"); $a->display($c); ?>
<? } ?>
<br/><br/>
<a href="<?=DIR_REL?>/"><?=t('Back to Home')?></a>.


if you know atleast some html it is extremely easy to edit
AlbertPotato replied on at Permalink Reply
AlbertPotato
Yes, but what would be the best practice for altering this to redirect folks to a Site Map page (for example) when they go to a bad URL?

I know starting off by copying /concrete/single_pages/page_not_found.php to /single_pages/page_not_found.php, but then what? Is there some c5 function for redirecting?
aluion replied on at Permalink Reply
I've tested redirects using the PHP header() method. This seems to work at first. However, it breaks the Content block's functionality if you try to edit one later. There's probably a way to get the header() method to work, but it would likely require someone more intimate with the Concrete5 base code to develop.

You can still use the "meta refresh" method to create a redirect. While this method is not recommended due to browser-compatability, accessibility concerns, and the fact that it interferes with your browser's back functionality, it is the only method I know of that you can -currently- use with concrete 5.

Simply add this to your /single_pages/page_not_found.php file:

NOTE: Remove the <?PHP and ?> from the code block before using. This is HTML, not PHP code.
<a href = "/">Click here if not redirected</a>
<meta http-equiv="refresh" content="2;url=/" />


As it stands, this will redirect you to your site's main page. You can also redirect to another page by using your page's alias.

So, if you have a page with an alias of "test", and you are using "pretty URLs" (check sidewide settings), you can use:

Redirecting you to test page. <a href = "/test">Click here if not redirected</a>
<meta http-equiv="refresh" content="2;url=/test" />


If you are not using pretty URLs, or you aren't sure whether you do or not, then you can use:

Redirecting you to test page. <a href = "/index.php/test">Click here if not redirected</a>
<meta http-equiv="refresh" content="2;url=/index.php/test" />


Note that you must change two portions of the above code (three, if you want it to make sense) in order to redirect to a different location. Replace all instances of the word "test" with whatever page alias you wish to use as a redirect.

Technical Notes:
This method passes no errors to the browser. Therefore, Google and other search engines may not properly cache your website if you have a lot of broken links.

This method also disrupts the Back button functionality of your user's browser. If a user tries to go back to the page which had the broken link, they'll have to do so before the refresh is sent. You can change the refresh delay by altering the number "2" in the example above to whatever you prefer.

This method is NOT standards compliant, and will confuse people using accessibility software such as screen readers.

So, as a web developer, I don't recommend it. As a user, I don't recommend it. As a blind person, I definitely don't recommend it. But if you have a small website, and it makes things more convenient, it's there for you to use.

If someone can get the PHP header redirect to work (without breaking the content block), it would be a far-prefered method, though it has its drawbacks as well. At least it's still (somewhat) W3C compliant, and it doesn't break screen readers or interfere with the browser.
AlbertPotato replied on at Permalink Reply
AlbertPotato
Aluion, that's exactly what I've already tried and ended up doing for now: First tried php's header function and it broke tiny_mce and now use the meta-refresh method. It's certainly less than ideal and this must be something that c5 can handle more elegantly as they've thought of everything else! I'll post here if I get a better solution in place.
AlbertPotato replied on at Permalink Reply
AlbertPotato
Remo has posted another possible solution for 404s here:
http://www.codeblog.ch/2010/01/concrete5-custom-404-page/...

No redirect, but displaying a site map within page_not_found.php. Worked great for me since I was just trying to redirect folks to a site map anyway.
Remo replied on at Permalink Reply
Remo
Glad you found it useful. I just wanted to add something more than just a custom theme and thought a sitemap might be useful (:
SmushyPillows replied on at Permalink Reply
I sent out a marketing email that has the wrong link on it. The link goes to an identical page on a different web host (too slow, migrated site to new web host, etc...)

What I'd like to do is have users redirected to the proper web site from the landing page. How do I do that in C5? I know how to use the header() function, but WHERE???

Thank you !
Remo replied on at Permalink Reply
Remo
if you want to make sure that old links still work (map old to new pages)

check this:http://www.concrete5.org/community/forums/chat/smart-404-page/#2469...

I never finished it because we didn't have any budget for it wouldn't take a lot of time to finish it as an addon where you can enter the old url and pick the page where users should be redirected..