Jump to content
icreation

Redirect 301 causing a server error

Recommended Posts

I built best-of-scotland.co.uk on Processwire and have a redirect problem.

Tried method 1:

If I add the line to the .htaccess file I get a site error. At the bottom or the top of  the file I tried adding

Redirect 301 /index.php/contact http://best-of-scotland.co.uk/contact/

Tried Method 2:

Using the redirect module (http://modules.processwire.com/modules/process-redirects/) does not seem to work at all.

For example this page http://www.best-of-scotland.co.uk/index.php/contact was the old page and we are trying to get it to redirect to http://www.best-of-scotland.co.uk/contact.

Is there a way to redirect an old site with SEO rewritten URLs to the new site?

Share this post


Link to post
Share on other sites

Method 1 does not work because the syntax is not correct. Try adding the redirect like this in the .htaccess, before Pw does handle the request itself:

<IfModule mod_rewrite.c>

  RewriteEngine On
  AddDefaultCharset UTF-8

  #Redirect here
  RewriteRule ^/index.php/contact$ /contact/ [R,L]

Why does Redirects not work? Any errors?

If your page-names in ProcessWire have the same name as on your old site, you could setup a rule like this:

RewriteRule ^/index.php/(.*)$ /$1/ [R,L]
  • Like 2

Share this post


Link to post
Share on other sites

I'd like to dig up this topic as I have a similar problem...

I had a site with two separate sections under one domain, which then was split up into two separate sites with their own domains.

Now I'm trying to set 301 redirects to all broken links.

I added this to my .htaccess:

RedirectMatch 301 /new/(.*) http://www.newdomain.com//$1 

So if you type in www.olddomain.com/new/about you should be redirected to www.newdomain.com/about.

This does work, sort of. But the result is www.newdomain.com/about?it=new/about, which causes a page not found error.

How do I get rid of the ?it=new/about part?

Share this post


Link to post
Share on other sites

Try adding this line before your redirect:

RewriteCond %{THE_REQUEST} ^.*/index.php

Also, remove the second forward slash: //$1 should be /$1

Share this post


Link to post
Share on other sites

I already have that line, followed by a RewriteRule...

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,NC,L] 

This is for redirecting to the base url, so if someone enters mydomain.com/index.php he gets redirected to mydomain.com

But even if i remove the rewrite rule line, still the same effect.

I removed the typo with the second slash, but that seemed not to be the problem.

I don't really understand how this part "?it=something/else" is generated... Is there a way to cut it off just for the redirect?

Share this post


Link to post
Share on other sites

Try this:

Redirect 301 /new http://www.newdomain.com

That should keep things simple.  Nevermind - that won't obviously take care of the pages below /new/

If it still doesn't work, try removing your index.php redirect as a way of testing this first.

Share this post


Link to post
Share on other sites

thanks. the thing is, the redirect is actually working... it's just the additional "?it=blah/bleh" part that makes the url unusable.

I just don't know how to remove it (or prevent PW from adding it automatically)... any ideas?

Share this post


Link to post
Share on other sites

Just to clarify things first.

You have an actual page on your new domain that is newdomain.com/about/ ?

First I wanted to mention that all urls in ProcessWire by default are with a trailing slash (unless you change template settings of this). And acessing newdomain.com/about will redirect you to /about/

Share this post


Link to post
Share on other sites

yes, the page I'm redirecting to is the actual page newdomain.com/about/ , redirecting from the (no longer existing) olddomain.com/new/about/

the result is the same with or without the trailing slash...

can anyone explain to me, why this ?it=/new/about/ part is appended at all in the first place? i just don't understand why and how this is happening...

Share this post


Link to post
Share on other sites

It's coming from ProcessWire also set in .htaccess.

I'm not sure depends where you set your redirect rule. It would be at the top before processwire ones.

If that's already the case, I think you'd maybe need a different rule to sort that out.

Share this post


Link to post
Share on other sites

Ah, I think I'm getting closer... this rule is where the path is appended for use in processwire

RewriteRule ^(.*)$ index.php?it=$1 [L,QSA] 

I solved it with a RewriteRule instead of a redirect

RewriteCond %{REQUEST_URI} ^.*/new/(.*)
RewriteRule ^new/(.+)$ http://www.newdomain.com/$1  [R=301,L]

RewriteRule ^new/(.*)$ http://www.newdomain.com/$1  [R=301,L]

I put this before all the other rewrite conditions. It redirects all requests containing the /new/ path to the new domain homepage, and also appends any path segments which might come after /new/. So www.olddomain.com/new/about/ becomes www.newdomain.com/about/ ...which is exactly what I wanted.

Thanks for pointing me in the right direction!

-------------------------------

Edit: the rewrite condition is not even necessary, and to execute the rule for just www.olddomain.com/new/, the + has to be replaced by a *.

Yay! :)

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By stanoliver
      Hi! 
      The following code snippet is part of my markup simple navigation and the url_redirect (url field in the backend) just works fine when I put an special custom url into the url_redirect field.
      <?php $nav = $modules->get("MarkupSimpleNavigation"); // topnav $current = $page->rootParent(); // current root page // subnav echo $nav->render(array( 'max_levels' => 2, 'item_tpl' => '<h4><a class="g8-bar-item g8-hover-black" href="{url_redirect|url}">{title}</a></h4><hr class="sidenav">', 'collapsed' => true, ), $page, $current); ?>  In my seperated breadcrumb navigation I use the following code snippet
      <?php foreach($page->parents()->append($page) as $parent) { echo "<li><a href='{$parent->url_redirect|url}'>{$parent->title}</a></li>"; } ?> Now to the problem: In my first code snippet above the
      url_redirect|url 
      works just fine but when I try something similiar in the second code snippet
      $parent->url_redirect|url
      I produce an server error How do I have to change the second code snippet so that it works in the correct way as the first code snippet does?
    • By Orkun
      Hi Guys
      How can I make a redirect inside the .htaccess to my custom maintenance.html file when any URL of my Website is accessed except the processwire admin (www.example.com/processwire/).
      Because I want that my User's still can access the website when they are loggedin in Processwire.
      When the current url starts with /processwire or if there is a processwire-login-cookie (Is there a cookie when user is logged in Processwire?) available the redirect should not work. Otherwise it should work.
      How can I achieve this?
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I'm trying to automatically redirect a logged-in user to a custom profile page using $session->redirect() and need to add $user->name to the redirect path.
      All my attempts appear to have failed:
      $session->redirect('/user-profile/')->name; $session->redirect('/user-profile/')->$user->name; $session->redirect('/user-profile/' . get($user->name . '/')); $session->redirect('/user-profile/' & get($user->name)); Can anyone point out where I am going wrong?
    • By Marco Angeli
      Hi there,
      I added a ssl certificate to my site and I'd like to redirect every single http url to its new https version
      So I added this code in the .htacces file, after the RewriteEngine On :
      Redirect 301 /about https://www.mysite.it/about
      Unfortunately this is now working: I get the "too many redirects" error.
      The following code works, but it's a bulk redirection to the home page, something I don't want for SEO reasons (https://moz.com/blog/save-your-website-with-redirects😞
      RewriteCond %{HTTP_HOST} mysite\.it [NC]
      RewriteCond %{SERVER_PORT} 80
      RewriteRule ^(.*)$ https://www.mysite.it/$1 [R,L]
      Any suggestions?
×
×
  • Create New...