Jump to content

ProcessRedirects with WAMP Server


LedZepmann
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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

×
×
  • Create New...