Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect. Need help. Having a hard time.

         

overstride1

5:20 am on Sep 24, 2009 (gmt 0)

10+ Year Member



I'm trying to redirect http://www.example.com/asp.pl?_puri=astore.amazon.com%2Fthegi02-20%2Fdetail%2FB0001L0DFA%2Fassid to the front page of my site and can't get it to work. I've tried many different methods of redirecting. Can anyone help?

[edited by: jdMorgan at 1:27 pm (utc) on Sep. 24, 2009]
[edit reason] example.com [/edit]

g1smd

7:07 am on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What have you tried, and what exactly happened?

The description "not working" for code we can't even see is of no help here.

Be aware that RewriteRule cannot see parameters attached to a URL.

You need a preceding RewriteCond to detect those.

There's very many prior examples here, at least several each week, to pick for starters.

overstride1

3:15 pm on Sep 24, 2009 (gmt 0)

10+ Year Member



I used in the .htaccess file:

Redirect 301 /asp.pl?_puri=astore.amazon.com%2Fthegi02-20%2Fdetail%2FB0001L0DFA%2Fassid [mainpage.com...]

and it works with regular html files, but not with those URLs. Any idea why?

jdMorgan

3:19 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The mod_alias "Redirect" directive can 'see' only URLs, and not the query strings (data) attached to them.

Use mod_rewrite instead of mod_alias, and use a RewriteCond examining %{QUERY_STRING} to match and capture parts of the query string for re-use in the new URL.

The resources cited in our Forum Charter may prove useful to you.

Jim

[edited by: jdMorgan at 3:25 pm (utc) on Sep. 24, 2009]

overstride1

3:22 pm on Sep 24, 2009 (gmt 0)

10+ Year Member



I'm new to rewrites and remods. All that went over my head. Can you give me an example script? I would really appreciate it.

overstride1

4:01 pm on Sep 24, 2009 (gmt 0)

10+ Year Member



If anyone can give me a code to have that URL redirected I'd be more than happy to pay. Please let me know. I'm in a hurry.

jdMorgan

4:08 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As stated in our Forum Charter, this is a discussion forum, and we cannot write code for all who request it, given the small number of volunteer contributors and their available resources. Therefore, any new code development must be a 'guided self-help' project.

From above:

The resources cited in our Forum Charter may prove useful to you.

We also have a site search facility to turn up hundreds of previous examples, and there are several related threads in our Forum Library (Please see links at the top of this page).

To dull any perceived 'edge' to this response, I'd like to state that "handing you what we think is the solution to your problem" and saying, "Here, just use this" is doing you no favors; The code could be a perfectly-correct solution to the wrong problem.

This expedient would also leave you with no understanding of the solution, and no redress should a problem arise other than to post again in this (or another) forum and hope that your luck is better the second time. We'd prefer to "teach you to fish" instead of "handing you a fish," as it were.

While server configuration code tends to be compact, it is also obscure and very powerful; Very small changes can have very large (and often detrimental) effects on the operation (and success) of your site. One single typo can immediately take down your server (if you're very lucky), or it can sit there causing subtle problems, quietly destroying your search engine rankings over time. As with a chainsaw, it is best to understand how it operates before trying to use it.

Jim

overstride1

6:49 pm on Sep 24, 2009 (gmt 0)

10+ Year Member



I tried:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^_puri=astore.amazon.com%2Fthegi02-20%2Fdetail%2FB0001L0DFA%2Fassid$
RewriteRule ^/asp.pl$ http://www.example.com? [L,R=301]

and it doesn't work. Any ideas?

g1smd

7:58 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What is meant by "doesn't work"?

What did you expect it to do?

What did it do?

How do those things differ?

Does this code sit in your httpd.conf or your .htaccess file?

If .htaccess, there's one simple change to make with the leading slash on the pattern.

jdMorgan

8:27 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In .htaccess:

RewriteCond %{QUERY_STRING} ^_puri=astore.amazon.com[b]\%2F[/b]thegi02-20[b]\%2F[/b]detail[b]\%2F[/b]B0001L0DFA[b]\%2F[/b]assid$
RewriteRule [b]^asp\.p[/b]l$ http://www.example.co[b]m/?[/b] [R=301,L]

The "%" signs have special meaning to mod_rewrite unless escaped as shown, the leading slash will not be present on the requested URL-path in .htaccess, and you must specify the URL-path "/" as a minimum on the substitution URL in order to avoid a second redirect caused by mod_dir attempting to add it if missing.

It is also possible that the %2F sequences in the query string will be un-escaped before they are tested, in which case. you'd want:


RewriteCond %{QUERY_STRING} ^_puri=astore.amazon.co[b]m/t[/b]hegi02-2[b]0/d[/b]etai[b]l/B[/b]0001L0DF[b]A/a[/b]ssid$

Jim