Jump to content
anthonygustin

.htaccess 301 Redirect Issue

Recommended Posts

Hey all, things had been going well remapping a site from one domain to another, but hit a snag and have searched for hours and don't know how to continue. 

1) I was moving everything from thepaleofix.com to dranthonygustin.com

2) I moved every single path individually with redirects like this: Redirect 301 /category/post http://www.dranthonygustin.com/category/post

Everything smooth sailing until today when through webmaster tools (to say site address as moved) I had to execute "Redirect 301 / http://www.dranthonygustin.com" -- now some of the urls go through and some don't include the / after the .com extension. 

For example:

http://www.thepaleofix.com > http://www.dranthonygustin.com no problem 

http://www.thepaleofix.com/resource/purepharma-m3-review/http://www.dranthonygustin.com/what-does-magnesium-do/ no problem

BUT a bunch of the URLs then don't push... For example:

http://www.thepaleofix.com/recipe/paleo-jam > http://www.dranthonygustin.comrecipe/paleo-jam/ (notice NO / after the .com extension)

and http://www.thepaleofix.com/wp-admin > http://www.dranthonygustinwp-admin (which of course leads to dead link)

There are a bunch of paths that do this, that I checked before and were working, such as: 

Redirect 301 /recipe/paleo-jam http://www.dranthonygustin.com/simple-vanilla-berry-paleo-jam/
 

Any idea why after implementing the / redirect, why it broke some of the redirects and not all? 

 

Thanks! 

Share this post


Link to post
Share on other sites

you would need something like this in your old site's root folder htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} www.thepaleofix.com.com [NC]
RewriteRule ^(.*)$ http://www.dranthonygustin.com/$1 [L,R=301]

Once the URLs are all forwarding from the old domain, you would then use a combination of htaccess 301, and Jumplinks (module) to handle the differences.

because with the above rules if someone requests

http://www.thepaleofix.com/resource/purepharma-m3-review/

they will definitely be redirected to

http://www.dranthonygustin.com/resource/purepharma-m3-review/

so then your local 301 or Jumplink would do the 2nd 301 to the new page

  • Like 2

Share this post


Link to post
Share on other sites

Thanks!

 

Right, but I already had set up about 180 of the old URLs to new URL slug paths -- would I have to go through and then redo everything separately? 

Share this post


Link to post
Share on other sites
1 hour ago, anthonygustin said:

 already had set up about 180 of the old URLs to new URL slug paths

where are those - on the old domain?

 

Share this post


Link to post
Share on other sites

ok right, well my technique uses 2 redirects, but does guarantee that every page on the site gets redirected to it's new counterpart without having to do anything extra.

 

  • Like 1

Share this post


Link to post
Share on other sites
On 9/28/2016 at 3:59 AM, Macrura said:

ok right, well my technique uses 2 redirects, but does guarantee that every page on the site gets redirected to it's new counterpart without having to do anything extra.

 

hey can you help me here, I tried your method above but it doesn't work

https://processwire.com/talk/topic/20554-mysitecom-redirected-you-too-many-times/

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 jploch
      Hey folks,
      currently Iam working on a website for one of my clients and I need some advice on how to approach this in PW.
      The website is for a company, that offers holiday houses in two locations. 

      The client wants the homepage to show the first location. Normally I just have a home template for the first page, but here the URL should reflect that you are in Location 1. So when you visit the URL casamani.com it should redirect to casamani.com/location-1. Not sure if this makes sense at all.

      Whould it be bad for SEO and performance reasons to redirect home to the Location-1 page?
      Another approach would be to render the Location-1 template on the home template or do an include like discussed here.
      Here is how the tree looks:
      – Home
      – Location 1 (Homepage)
           – Creation
           – Adventure
           – Sustainability
      – Location 2 
           – Creation
           – Adventure
           – Sustainability

      Thanks for looking into this!
    • By wwwouter
      Some context: I want to use PHP variables in my CSS (more info below) and found a solution on CSS-tricks that looks fairly elegant and somewhat solid to me. It's pretty simple, I created a file style.css.php inside the site/templates/ directory and load that in my page head. In style.css.php is the following:
      <?php header("Content-type: text/css; charset: UTF-8"); header("Charset:utf-8"); if ($homepage->hero_image) { echo <<<CSS .hero { background: url($homepage->hero_image->url) no-repeat; } CSS; } ?> Because of the following RewriteCond (line 373) in the htaccess file the server sends a 403 error back when the file is requested:
      # Block access to any PHP or markup files in /site/templates/ or /site-*/templates/ RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/.*\.(php|html?|tpl|inc))($|/) [NC,OR] (My htaccess file is @version 3.0 and @htaccessVersion 301)
      This is how I thought I could fix that (based on these answers on stack overflow) but it does not work:
      # Block access to any PHP or markup files in /site/templates/ or /site-*/templates/ RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/((?!style\.css).)*\.(php|html?|tpl|inc))($|/) [NC,OR] I tested the rule with htacess tester and htaccess check and both worked for me, but on my site I still get a 403 instead of the file.
      I'm working on localhost, using MAMP (not sure if that's relevant).
      A bit more about what I want to do achieve specifically:
      I want to use an image as a background-image for an element, not place it as an image. This image is provided by the user via a field and can therefore change.
      I know I can achieve this like this:
      echo "<section class='hero' style='background-image: url($page->hero_image->url)'></section>"; But I would prefer a method other than inlining because of scalability and cleanliness. (I admit the extra link in the page head is not ideal either)
       
      P.s. this is my first post here, I hope it's submitted in the right forum and my explanation is clear.
    • By RDC
      Is the right way to get Processwire to skip a folder (ie not process it as its running a different CMS) to put
      RewriteCond %{REQUEST_URI} !^/shop/.*$
      just before 
      RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]
      in .htaccess?
    • By Spiria
      I am writing here instead of the ProCache forum because I have the impression that several nginx experts could solve this. In its new version, Procache proposes new .htaccess rules that are difficult to translate into nginx rules. We currently have a problem with the trailing slash of URLs which gives us a bad score in SEO analysis tools such as semrush.com. 
      Indeed, a canonical URL is either without or with "/", but cannot be served by both options. Although ProcessWire without ProCache respects this rule, ProCache has no difficulty serving both, which is considered an SEO optimisation fault. I believe that ProCache version 2 solves this problem with these new rules, but I can't understand the following. Does anyone have any idea how to translate this into a nginx rule?
      Attached also the whole proposed .htaccess for ProcessWire.
      # PROCACHE v2/31885be14d6cfb4b2b0d3e533260bded -------------------------------------------------- RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{QUERY_STRING} !.*=.* RewriteRule ^.*/$ - [E=pwpcstep:pour,E=pwpcname:index] RewriteCond %{ENV:pwpcstep} "=pour" RewriteCond %{HTTP_COOKIE} !^.*(wire_challenge|wires_challenge).*$ RewriteRule ^.*/$ - [E=pwpcstep:stir,E=pwpcpath:%{DOCUMENT_ROOT}/site/assets/ProCache-00478359c5e65dbada1075bfbd4] RewriteCond %{ENV:pwpcstep} "=stir" RewriteCond %{ENV:pwpcpath}/$0/%{ENV:pwpcname}.html -f RewriteRule ^.*$ - [E=pwpcstep:drink,E=pwpcfile:$0/%{ENV:pwpcname}.html] RewriteCond %{ENV:pwpcstep} "=drink" RewriteRule ^(.*) %{ENV:pwpcpath}/%{ENV:pwpcfile} [L] <ifModule mod_headers.c> Header set X-PWPC "ProCache" env=pwpcstep Header set X-Powered-By "ProcessWire CMS, ProCache" env=pwpcstep </ifModule> RewriteCond %{REQUEST_URI} "^/~?[-_.a-zA-Z0-9/]*$" # /PROCACHE -------------------------------------------------------------------------------------  
      .htaccess-procache
    • By theoretic
      Hi guys and ladies! And thanks for Processwire!
      It appears i've got an interesting issue concerning the template-settings-based PW redirects dealing with access control. Any PW template has some access control options i.e. "Login redirect URL or page ID to render". If this option is used for a page having a template with this option filled, a redirect will occur if user is not logged in and/or has insufficient access rights.
      I like to hook PW events. In one of my current projects i decided to write an addHookBefore('Session::redirect', ...) which should store the page we are being redirected from. With "regular" redirects like $session->redirect('/somewhere/') this hook works like a charm. But it was strange to see that it doesn't work with the template-settings-based redirect.
      I'm too dumb to dive deep inside PW and to examine the whole PW session mechanism. But it could be rather logical if ANY redirect ( no matter template-settings-based or using $session->redirect() ) could be hooked in the same manner.
      Okay okay i can forget about template-settings-based redirect and write my own. Just a couple of lines of code, and it works. But it's less elegant than hooking the template-settings-based redirects.
      So am i missing something? It this behavior a bug, or is it intended by PW team? Thanks in advance for any comment!
×
×
  • Create New...