Jump to content

redirect old paths with .htaccess in multisite installation?


makari
 Share

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?

Link to comment
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/

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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]
Link to comment
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! 

Link to comment
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...

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...