0

I'm putting a new site live and need to redirect all the old pages to the relevant new ones. The issue is that the old site used PHP queries, whereas the new site doesn't.

This means that if I setup a redirect like so:

RewriteRule %{QUERY_STRING} range.php?type=baropt&item=01 [NC]
RewriteRule .* http://domain.com/range/bars/led-bar? [R=301,L] 

Instead of redirecting as it should, it simply displays a blank page with the message 'Disallowed Key Characters'.

I'm happy to setup manual redirects for the various pages (there's only around 80-90 in total). but can't workout how to do it. I've been told I'll need to use 'mod_rewrite, request_uri + query_string conditions' but that doesn't mean much to me.

OLD URL: domain.com/range.php?type=baropt&item=01

NEW URL: http://domain.com/range/bars/led-bar

Any ideas gratefully received!

Thanks in advance,

Tom

1

Did you actually mean this?

RewriteCond %{QUERY_STRING} range.php?type=baropt&item=01 [NC]
RewriteRule ^(.*)$ http://domain.com/range/bars/led-bar? [R=301,L] 

You should use RewriteCond, not RewriteRule is first line, as it'a conditional that applies to the rule, the rule itself is in second line. Also replace &amp ; with simple ampersand (unless you really have &amp ; in URL)

0

If you have imported the previous URL as some field, let's say, previous_url, you can use a template to help you create the redirects.

Access the template, copy the rules and paste them on your .htaccess file or NGINX location.

For NGINX

{exp:channel:entries channel="channel_name" limit="500"}
    rewrite ^/{previous_url} http://domain.com/template_group/template/{url_title} redirect;<br />
{/exp:channel:entries}

If everything work fine, replace redirect by permanent and restart nginx service.

For Apache

{exp:channel:entries channel="channel_name" limit="500"}
    RewriteRule ^/{previous_url} http://domain.com/template_group/template/{url_title} [L,R=302]<br />
{/exp:channel:entries}

If everything work fine, replace 302 by 301.

4
  • Hi Robson, thanks for your thoughts but I'm that still leaves the same issue. If I try to redirect from link on the old site that contains a query (range.php?type=baropt&amp;item=01) then rather than make the redirect, you simply get a blank page with just the message (Disallowed Key Characters.) Any ideas how to get around that? Oct 6 '14 at 7:22
  • This is strange, @TomPerkins, because the redirect happens before EECMS to run, on the server software.
    – Sobral
    Oct 6 '14 at 12:39
  • That's a good point. Maybe the redirect isn't working (due to it being a query) and therefore EE is trying to simply go to that URL and finding disallowed characters? I guess what we need to work out is how to redirect php queries (i.e. www.domain.com/range.php?type=baropt&amp;item=01) Oct 7 '14 at 7:41
  • 1
    You have made sure these rules are before any EE friendly URL/mod_rewrite rules in your .htaccess file right? Also when tinkering with Rewrites I find its sometimes easier to drop the EE friendly URL's while you work it out
    – Blatant
    May 4 '15 at 14:03
0

It's a bit pricey for what it does, but if you prefer to manage redirects from the CP, and think maybe there will be more in the future, than Detour Pro is a nice option: http://devot-ee.com/add-ons/detour-pro

1
  • Thanks for the suggestion Jeremy but the issue isn't making normal redirects, but rather making redirects from links that contain queries? Oct 6 '14 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.