1

I've been struggling with some htaccess redirects. I just spent some time reading and searching and couldn't get a solution that works with my scenario.

I'm in the process of making the 301 redirect for an old website (ASP) to a new one (Wordpress). The old pages has parameters query which I need to process but also remove 'http://' string from it to get redirect to work.

Example URL (old) to redirect looks like:

http://www.domain.org/index.asp?documentID=2410&utm_source=IT+Travel+Reminder&utm_medium=Informz%2FnetFORUM&utm_campaign=IT%2FTravel+Reminder%2FMonthly+Monthly+Travel+Reminder&zbrandid=4050&zidType=CH&zid=28841368&zsubscriberId=1036792259&zbdom=http://my.informz.net

redirected to:

http://www.domain.org/permalink-2410/?qs=true&utm_source=IT+Travel+Reminder&utm_medium=Informz%2FnetFORUM&utm_campaign=IT%2FTravel+Reminder%2FMonthly+Monthly+Travel+Reminder&zbrandid=4050&zidType=CH&zid=28841368&zsubscriberId=1036792259&zbdom=my.informz.net

and .htaccess code to redirect it:

RewriteCond %{QUERY_STRING} ^documentid=2410(&.*)$ [NC]
RewriteRule ^index\.asp(.*):(.*)$  http://www.domain.org/permalink/?qs=true%1%2 [L,R=301,QSA]

but somehow is not working as I have expected when

RewriteCond %{QUERY_STRING} ^documentid=2410(&.*)$ [NC]
RewriteRule ^index\.asp$ http://www.domain.org/permalink/?qs=true%1 [L,R=301,QSA]

works fine when I will remove http:// or : from a query string.

Where do I have made mistake?

Thanks!

JackTheKnife
  • 3,795
  • 8
  • 57
  • 117

1 Answers1

1

Try this rule:

RewriteCond %{QUERY_STRING} ^documentid=(\d+)(&.+?)http://(.+)$ [NC]
RewriteRule ^index\.asp$ http://www.domain.org/permalink-%1/?qs=true%2%3 [L,R=302,NC,NE]

Make sure to clear browser cache before testing this.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Somehow is not working for whole `RewriteCond` - works fine for `RewriteCond %{QUERY_STRING} ^documentid=(\d+)` only – JackTheKnife Jun 02 '15 at 18:54
  • I have tested this rule on my Apache and it worked fine. Make sure this is first rule below `RewriteEngine On` line. URL you must enter to test should be: `http://www.domain.org/index.asp?documentID=2410&utm_source=IT+Travel+Reminder&utm_medium=Informz%2FnetFORUM&utm_campaign=IT%2FTravel+Reminder%2FMonthly+Monthly+Travel+Reminder&zbrandid=4050&zidType=CH&zid=28841368&zsubscriberId=1036792259&zbdom=http://my.informz.net` – anubhava Jun 02 '15 at 19:04
  • I have `RewriteEngine On` and I have tested that rule on two different servers running cPanel - both are not able to get pass that condition – JackTheKnife Jun 02 '15 at 20:16
  • 2
    It looks like WP htaccess rules (some kind of additional) create issues with your solution which BTW works fine on a clean htaccess file. Will dig deeper how to marry it with existing one. Thanks! – JackTheKnife Jun 02 '15 at 20:53