Hi guys,
I have a requirement in MODx revo to redirect an unpublished url to a page other than the 404 page.
Basically there are some promo pages in a container.
IF the user hits them and they are unpublished, I want to redirect them to the homepage, rather than to my pre-defined 404.
Any ideas?
J
301 Redirect in .htaccess
Or create those resources as weblinks until you are ready to publish the content.
Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
-
☆ A M B ☆
- 3,112 Posts
You can use plugin (OnPageNotFound) to preg_replace the $modx->resource->_output to match the <a href="[ [~unpublished_promo]]">:
1. check (eg.) with switch-case to get a TV (just a helper) to identify whether it is a promo page or not.
2. if YES, redirect to homepage.
3. if NOT, do at your will.
What do you think?
Rico
Genius is one percent inspiration and ninety-nine percent perspiration.
Thomas A. Edison
MODx is great, but knowing how to use it well makes it perfect!
www.virtudraft.com
Security, security, security! |
Indonesian MODx Forum |
MODx Revo's cheatsheets |
MODx Evo's cheatsheets
Author of
Easy 2 Gallery 1.4.x,
PHPTidy,
spieFeed,
FileDownload R,
Upload To Users CMP,
Inherit Template TV,
LexRating,
ExerPlan,
Lingua,
virtuNewsletter,
Grid Class Key,
SmartTag,
prevNext
Maintainter/contributor of
Babel
Because it's hard to follow all topics on the forum, PING ME ON TWITTER
@_goldsky if you need my help.
Hi there,
I tried an approach like this, now im getting an error.
If I try to access a resource in the OnPageNotFound event I get this error:
Fatal error: Call to a member function get() on a non-object in blah.snippet.php
When I do a var_dump on $modx->resource it is NULL?
Something else must be broke right for this to be null?
Thanks,
J
-
☆ A M B ☆
- 3,112 Posts
My bad, of course it is null, that's because it can not (normally) be found.

doh.
You
only need to check if there is a promo-TV that attached to that (supposed to be a) missing page.
Sounds logic to you?
Rico
Genius is one percent inspiration and ninety-nine percent perspiration.
Thomas A. Edison
MODx is great, but knowing how to use it well makes it perfect!
www.virtudraft.com
Security, security, security! |
Indonesian MODx Forum |
MODx Revo's cheatsheets |
MODx Evo's cheatsheets
Author of
Easy 2 Gallery 1.4.x,
PHPTidy,
spieFeed,
FileDownload R,
Upload To Users CMP,
Inherit Template TV,
LexRating,
ExerPlan,
Lingua,
virtuNewsletter,
Grid Class Key,
SmartTag,
prevNext
Maintainter/contributor of
Babel
Because it's hard to follow all topics on the forum, PING ME ON TWITTER
@_goldsky if you need my help.
-
☆ A M B ☆
- 3,112 Posts
This is a dirty hack, IDK if this works for FURL, but $modx->resourceIdentifier does exist.
if ($modx->event->name == 'OnPageNotFound') {
echo __LINE__ . ' : $modx->resourceIdentifier= ' . $modx->resourceIdentifier;
die();
}
Rico
Genius is one percent inspiration and ninety-nine percent perspiration.
Thomas A. Edison
MODx is great, but knowing how to use it well makes it perfect!
www.virtudraft.com
Security, security, security! |
Indonesian MODx Forum |
MODx Revo's cheatsheets |
MODx Evo's cheatsheets
Author of
Easy 2 Gallery 1.4.x,
PHPTidy,
spieFeed,
FileDownload R,
Upload To Users CMP,
Inherit Template TV,
LexRating,
ExerPlan,
Lingua,
virtuNewsletter,
Grid Class Key,
SmartTag,
prevNext
Maintainter/contributor of
Babel
Because it's hard to follow all topics on the forum, PING ME ON TWITTER
@_goldsky if you need my help.
I guess if $modx->resourceIdentifier; is present I can assume this is an unpublished page that exists, and if its not set then this is a page that has been completely removed.
This might work, i'll try it tomorrow.
TY for the help, greatly appreciate it.