makari

redirect old paths with .htaccess in multisite installation?

Recommended Posts

Hello,

I need to redirect the old paths after migration to a multisite PW installation.

There are 3 domains and small differences between paths

i.e.



old path: domain-2/?text
new path: domain-2/text or domain-2/new_text


I try it via .htaccess (in the root direction) with an 301 redirect:



redirect 301 domain/old_path domain/new_path


-> generates an 500 server error

What is wrong? How to do that?

Share this post


Link to post
Share on other sites

Hello Makari,

When you would like to redirect an old url to a new url you need to include the complete url for the new location (including http://)

E.g.

Redirect 301 /old_path/old_sub_path http://www.newdomain.com/new_path/new_sub_path

In general it's also a good practice to redirect users from the toplevel domain to it's www. variant (or the other way around. from www. to the toplevel domain). You can set this up with mod_rewrite. The example below will redirect users from domain.com to www.domain.com.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

One other way is to install one of the modules below to handle the redirects from inside ProcessWire:

http://modules.processwire.com/modules/process-jumplinks/

http://modules.processwire.com/modules/process-redirects/

Share this post


Link to post
Share on other sites

So. I have installed ProcessRedirect because it looks more simple then jumplink.

post-2747-0-22535200-1464792771_thumb.pn

Testet it, but it takes no effect.

May be, because it is a multisite installation??

Share this post


Link to post
Share on other sites

Hi Makari,

Being the developer of Jumplinks, I haven't used ProcessRedirects in a long time, so not sure if it supports query strings, but Jumplinks does. Once installed, the redirects above should work just fine for you.

Jumplinks is, in fact, quite simple, but may come across a little more complicated because it has more features and more options to choose from. That said, you can use Jumplinks the same way you would use ProcessRedirects. Just create a new Jumplink, and specify the Source URI and Destination URI/URL/Page.

Please give it a try and let me know if it works for you.

Note that this could also be done with htaccess and mod_rewrite, but you don't want to get caught in the position where the htaccess file gets updated by ProcessWire and your redirects disappear.

  • Like 3

Share this post


Link to post
Share on other sites

Hi Mike, unfortunetly it is the same with jumplinks: Installed, configured like redirekt (screeenshot above) but no effect.

I have turned on the debug mode and tested again – jumplinks said:

Created by admin on 2016-06-02 14:20:49 (6 minutes ago)
Last updated by admin on 2016-06-02 14:20:49 (6 minutes ago)
This jumplink hasn't been hit yet.

hmm... 

edit:

I have also turned on the 404 monitor. But I dont get any 404 errors – every time I call an old path it turns me to the index page.

Share this post


Link to post
Share on other sites

Hi Mike, unfortunetly it is the same with jumplinks: Installed, configured like redirekt (screeenshot above) but no effect.

I have turned on the debug mode and tested again – jumplinks said:

Created by admin on 2016-06-02 14:20:49 (6 minutes ago)
Last updated by admin on 2016-06-02 14:20:49 (6 minutes ago)
This jumplink hasn't been hit yet.

hmm... 

edit:

I have also turned on the 404 monitor. But I dont get any 404 errors – every time I call an old path it turns me to the index page.

Right, of course! Silly me... When requesting /?something, it's actually a request to the home page, which exists. Because it exists, Jumplinks can't touch it.

So you'll need to use htaccess for these. Place the code block below directy underneath RewriteEngine On.

RewriteCond %{QUERY_STRING} ^lhre_Ansprechpartner/?$ [NC]
RewriteRule ^$ /ihre-ansprechpartner/ [QSD,R=302,L]

You'll need to do this for each redirect you want.

Alternative using Jumplinks:

If you want to do this in one fowl sweep using Jumplinks, then you only need to do the following:

Instead of the above condition and rule for each URI, use this only:

RewriteCond %{QUERY_STRING} ^(\w+)/?$
RewriteRule ^$ /_redirect/%1/ [QSD,R=302,L]

Then create a jumplink with the following:

Source: _redirect/{path}/?

Destination: {path}/

Now, requesting domain.com/?lhre_Ansprechpartner/ will first redirect to domain.com/_redirect/lhre_Ansprechpartner/ and then Jumplinks will convert that to domain.com/lhre-ansprechpartner/.

Please let me know if that works. :)

Edit: I see that your destination URLs differ. So instead of using the {path} wildcard, just create the jumplinks using the format shown above. So for the first one, the source would be _redirect/lhre_Ansprechpartner/? and the destination would be lhre-ansprechpartner/.

Edited by Mike Rockett
  • Like 2

Share this post


Link to post
Share on other sites
RewriteCond %{QUERY_STRING} ^(\w+)/?$
RewriteRule ^$ /_redirect/%1/ [QSD,R=302,L]

that - in the .htaccess file produces an 500 server error...  :huh:

What do you think about this two steps?

  1. Remove the question mark from the URL (with .htaccess)
  2. Redirect the URL with Jumplinks

Unfortunetly I'm a bloody newbe in .htaccess syntax and regular expressions so I did not really understand, what things like the two lines above do.

Share this post


Link to post
Share on other sites
RewriteCond %{QUERY_STRING} ^(\w+)/?$
RewriteRule ^$ /_redirect/%1/ [QSD,R=302,L]

that - in the .htaccess file produces an 500 server error...  :huh:

What do you think about this two steps?

  1. Remove the question mark from the URL (with .htaccess)
  2. Redirect the URL with Jumplinks

Unfortunetly I'm a bloody newbe in .htaccess syntax and regular expressions so I did not really understand, what things like the two lines above do.

Could you perhaps check your apache logs? That syntax is valid, and works on my system. Also, where exactly did you place the rule? It should be directly below RewriteEngine On.

That condition and rule does remove the question mark, but it also adds _redirect to the beginning. You could also just strip out that part, and use this:

RewriteRule ^$ /%1/ [QSD,R=302,L]

Share this post


Link to post
Share on other sites

part from the .htaccess file:

# ProcessWire requires mod_rewrite
# -----------------------------------------------------------------------------------------------

<IfModule mod_rewrite.c>

  RewriteEngine On
  AddDefaultCharset UTF-8  

### test  
RewriteCond %{QUERY_STRING} ^(\w+)/?$
RewriteRule ^$ /_redirect/%1/ [QSD,R=302,L]
### /test

  # -----------------------------------------------------------------------------------------------
  # If you only want to allow HTTPS, uncomment the RewriteCond and RewriteRule lines below.
  # -----------------------------------------------------------------------------------------------

will produce an 500 server error for all 3 domains...

For the first I wont to stop this try. There are no 404 errors and guests coming via old paths are landing on the index page. Not ideal but ok.

Thank you for your help, Mike! 

Share this post


Link to post
Share on other sites

part from the .htaccess file:

...

will produce an 500 server error for all 3 domains...

For the first I wont to stop this try. There are no 404 errors and guests coming via old paths are landing on the index page. Not ideal but ok.

Thank you for your help, Mike! 

Weird indeed. Perhaps you could remove the QSD and add a question mark to the rule:

RewriteRule ^$ /_redirect/%1/? [R=302,L]

Both do the same thing (so far as I know), but not sure if one is deprecated...

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 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 Jennifer Stock
      Greetings. I would like to restrict access to certain sections of my organization's ProcessWire site using pubcookie. We are rolling out Shibboleth authentication later this year but for now, it seems I can only make use of our institution's single sign-on routine by utilizing rules in an .htaccess file. 
      I am wondering if there is a way to ask PW to apply these rules to certain pages in the site, whether via template type or location in the page tree:
      AuthType UWNetID PubcookieAppID "MyApplication" require type staff faculty  
    • 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?
    • By Jimmie Bragdon
      Wondering if anyone can help me get past a sticking point.  
      I'm setting up a Processwire instance in a multiple site setup (using Soma's multisite) to run several related websites.  I am getting stuck on the tagging system that I am using (adapted from a standalone PW site I'm running).  I have the tags themselves set up as Pages, and the Tags field on the related pages is and ASMselect field that populates based on the pages underneath /tags/ in the tree.  This system works fine on the standalone site.
      Where I am running into issues, is with trying to use them with the multisite setup.  Specifically, choosing the proper subset of pages for tags on the ASMselect input tab.  I want to choose only the tag pages for the site in question.  
      My tree is laid out like this:
      Multisite / 
                | site1.com
                     | subsections
                | site2.com
                     | subsections
                | Tags
                     | site1.com
                          | tagA
                          | tagB
                     | site2.com
                           | tagC
      So far, the best I've been able to do is to use  'parent.has_parent=/tags/' in the Custom Find or Selector String portion of the Selectable Pages section of the input.  This gives me the options of choosing tagA, tagB, or tagC on a page under site1.com.  What I'd like to find is a selector that allows me to only see tagA, tagB as options from a page under site1.com and only tagC on a page under site2.com.
      Elsewhere in my php templates, I'm using $page->rootParent->title to set the proper scope and URLs for things, but I have not found a way to get that to work in this field input setup.  I am trying to avoid creating specific fields and templates for each site, as unified templates were part of the purpose of going with a multisite install.
       
      Thanks in advance for any ideas.
    • By cosmicsafari
      Hi all,
      Just a quick question, when using the multisite module is there anything different that needs to be done in order to setup HTTPS for each of the domains its serving?
      Would a single SSL certificate for the main domain be enough to cover the others aswell or would you need multiple ceritficates one for each domain the mutlisite setup uses?