Jump to content

Recommended Posts

Posted

Hi All,

I'm moving a site from it's current CMS into Processwire. I've installed the ProcessRedirects module for this project. I'm working locally on Windows 7 using a virtual host (yourmrrooter.lo) with WAMP server.

The problem is the redirects simply do not work and instead I get a 404. 

Example: on the current live site, a page exists at www.yourmrrooter.com/drains-backing-up-total-drain/.  In my Processwire site, the page exists at yourmrrooter.lo/residential-plumber/clogged-drains/total-drain/.  I've set up a redirect in the module for /drains-backing-up-total-drain/ to point to /residential-plumber/clogged-drains/total-drain/ and I get a 404 page instead.

Are there any known issues / fixes?

Thanks :)

Posted

Module should be working fine... Are you getting an Apache 404, or a ProcessWire 404? If it's the PW 404, please could you send a screenshot of your redirect's edit page or a dump of the redirect directly from phpMyAdmin?

Posted

Hi @Mike Anthony,

It would appear to be a PW 404 as this page is displayed when attempting to call a redirect url: yourmrrooter.lo/http404 - see screen shots:

redirects.jpg

redirect-page.jpg

redirects-dump.jpg

Posted

I find it weird that you're being redirected to /http404/ - it's supposed to pass-through that URL, and display the URl that was entered (/drains-backing-up-total-drain/) in the address bar. So that's your problem there - perhaps another module is interfering, and forcing the http404 redirect? What have you got installed?

Posted

Hold the phone...

I have urlSegments enabled and am doing some localization depending on UrlSegment1, therefore changing text and phone numbers in pages - here's the code, which is placed in my _init.php file:

$countyPages = $pages->get("/service-locations/counties/")->children();

foreach ($countyPages as $cp) {

	$validCounties[$cp->title] = $cp->title;

}

if(isset($validCounties[$input->urlSegment1])) {

	$localpath = str_replace("","","$input->urlSegment1");

	$localphone = $pages->get("/service-locations/counties/$input->urlSegment1/")->countyphone;

	$localphoneshort = str_replace("-","","$localphone");

	$namecounty = $pages->get("/service-locations/counties/$input->urlSegment1/")->countyname;

	$name = str_replace("-"," ","$input->urlSegment1");

	$name = ucwords($name);

} else if($input->urlSegment1 == '') {

	$localpath = "";

	$localphone = $pages->get("/settings/")->phone;

	$localphoneshort = str_replace("-","","$localphone");

	$namecounty = $pages->get("/service-locations/counties/")->countyname;

} else {

	$nunya = $pages->get("/http404/");

	$session->redirect($nunya->url);
} 

if($input->urlSegment2) {

	$nunya = $pages->get("/http404/");

	$session->redirect($nunya->url);
}

So, it would appear that a redirect is being treated as a urlSegment1... 

Any way to get around this?  Perhaps I'll just have to set up redirects on the web server.

Posted

So, it would appear that a redirect is being treated as a urlSegment1...

It's evidently the last bits where you're redirecting to http404, which I don't think is the greatest idea. Perhaps you could just output a message if the segment isn't specified?

Posted

Instead of this:

} else {

    $nunya = $pages->get("/http404/");

    $session->redirect($nunya->url);
}

do the following:

else {
    throw new Wire404Exception()
}

Same of course also for the segment2 check

Posted

First, I commented out the entire block of code, and all this did was allow, for example, /drains-backing-up-total-drain/ to reload the page or allow any page I was currently on to reload. This is because URL Segments are ON for all pages.  To double check this, I turned off URL Segments for my home page template and voila, the redirects started working...

SO, it would appear that when URL Segments are enabled, this will disable the ProcessRedirects module!

Therefore, I'll be setting up redirects on the web server - hopefully that will work but won't know till I deploy the site.

Posted

Hi @adrian,

Instead of this:

} else {

    $nunya = $pages->get("/http404/");

    $session->redirect($nunya->url);
}

do the following:

else {
    throw new Wire404Exception()
}

Same of course also for the segment2 check

I've tried using the throw new Wire404Exception() in several PW projects and it never works for me - I get errors instead, like:

Error: Exception: (in C:\wamp\www\yourmrrooter\site\templates\_init.php line 122)

#0 C:\wamp\www\yourmrrooter\wire\core\TemplateFile.php(168): require()
#1 [internal function]: TemplateFile->___render()
#2 C:\wamp\www\yourmrrooter\wire\core\Wire.php(389): call_user_func_array(Array, Array)
#3 C:\wamp\www\yourmrrooter\wire\core\Wire.php(344): Wire->runHooks('render', Array)
#4 C:\wamp\www\yourmrrooter\wire\modules\PageRender.module(356): Wire->__call('render', Array)
#5 C:\wamp\www\yourmrrooter\wire\modules\PageRender.module(356): TemplateFile->render()
#6 [internal function]: PageRender->___renderPage(Object(HookEvent))
#7 C:\wamp\www\yourmrrooter\wire\core\Wire.php(389): call_user_func_array(Array, Array)
#8 C:\wamp\www\yourmrrooter\wire\core\Wire.php(344): Wire->runHooks('renderPage', Array)
#9 C:\wamp\www\yourmrrooter\wire\core\Wire.php(411): Wire->__call('renderPage', Array)
#10 C:\wamp\www\yourmrrooter\wire\core\Wire.php(411): PageRender->renderPage(Object(HookEvent))
#11 C:\wamp\www\yourmrrooter\wire\core\Wi

Where line 122 is the "throw new Wire404Exception();" command... The session redirect is my work-around for the above error.

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
×
×
  • Create New...