Forum Moderators: phranque

Message Too Old, No Replies

Redirect 301 with % character

% becomes %25 if 301 redirect is used

         

FromRocky

2:16 pm on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hope someone may know how.

I have decided to Redirect 301 of a site.

Most of the URLs in this site have a double colon ":". Google indexed these URLs inconsistently. Sometimes it converted ":" to "%3A" and others it kept the same. This is not a problem but the real problem is when these URLs were 301-redirected. All "%3A" became "%253A". Note that a character 25 was added. This means the new URLs has been redirected to wrong addresses.

My questions will be:
1. How to 301 redirect without "%" alternated?
2. How to change "%253A" back to the initial ":" by htaccess rewrite?

Thanks,
FromRocky

jdMorgan

2:33 pm on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We'll need to see one or more examples of your "incorrect" and "correct" URLs. It is likely that your URLs violated RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax [faqs.org] -- It is not allowed to use *any* character you like *anywhere* you like in a URL.

If your "::" sequence is appearing in part of the URL where it is not allowed, then User-agents such as browsers and robots are required to escape those characters, and that is why the %25 character is added.

This problem can be fixed, but it's a bit tricky.

Jim

FromRocky

2:54 pm on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Example:
From Inital
www.siteold.com/?q=widgets&sa=search&cof=FORID:1&...

Index:
www.siteold.com/?q=widgets&sa=search&cof=FORID%3A1&...

301 redirect
www.sitenew.com/?q=widgets&sa=search&cof=FORID%253A1&...

How to?
www.sitenew.com/?q=widgets&sa=search&cof=FORID:1&...
or at least to
www.sitenew.com/?q=widgets&sa=search&cof=FORID%3A1&...

jdMorgan

4:01 pm on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm... Something like this in /.htaccess should do it:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?(([^&]+&)*)cof=FORID\%(25)*3A([0-9]+)(&[^\ ]+)?\ HTTP/
RewriteRule ^$ http://www.new-example.com/?%1cof=FORID:%4%5 [NE,R=301,L]

This will take any query string attached to the "/" URL-path that has "cof=FORID%" in it, followed by zero or more '25' sequences, followed by '3A', remove all of that, and replace it with "cof=FORID:". Any preceding or trailing query name/value pairs, as well as the FORID number, are copied from the original query string to the new one.

To clarify, THE_REQUEST is the original client HTTP request header, exactly as received from the browser or robot. For example:

GET /?q=widgets&sa=search&cof=FORID%25253A1&foo=bar HTTP/1.1

-or-
GET /robots.txt HTTP/1.1

We use the server variable THE_REQUEST because no unencoding will have been applied to it, so we can see the characters exactly as they were sent by the client.

To keep this post simple, I have assumed that you have set up and enabled mod_rewrite in your /.htaccess file, and that you already have other working RewriteRules.

Jim

FromRocky

7:57 pm on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is great, Jim
Thanks,
I will try it when I can access to my htaccess file.

FromRocky

11:41 am on Jul 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have revised the codes for each subdomain

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^/]+/\?(([^&]+&)*)cof=FORID\%(25)*3A([0-9]+)(&[^\ ]+)?\ HTTP/
RewriteRule ^$ [new-example.com...] [NE,R=301,L]

It works very well.

However, I'm unable to rewrite it for a page
www.www.new-example.com/page.php?q=widgets&sa=search&cof=FORID%3A1&...

& 301 redirect to
www.www.new-example.com/page.php?q=widgets&sa=search&cof=FORID:1&...

FromRocky