Modrewrite redirect old search variables?

Regards,

DK

Ok same issue, I’m using the exact code you posted above, restarted server and this link is not rewriting (it appears still because of the encoded ? and = characters):

http://www.newhair.com/search/search.asp%3Fzoom_query%3Dsteve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0

If you modify the above link to have a ? and = like this:

http://www.newhair.com/search/search.asp?zoom_query=steve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0

The server will redirect it to here and inserts the server path. In addition, it does not fully translate “steve hartman” and only takes the first letter “s” :

http://www.newhair.com[COLOR="#FF0000"]/var/www/vhosts/newhair.com/httpdocs/[/COLOR]search.html?zoom_query=s

Getting there!

Also one more question, with this new .htaccess code, how could a do a single rewrite for another page? The old syntax i was using is no longer working?

RewriteRule ^treatment/fut-megasessions.asp$ megasessions.html [R=301,L]

rc,

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule .? http://www.newhair.com%{REQUEST_URI} [R=301,L]

RewriteCond %{QUERY_STRING} zoom_query=([^&])
RewriteRule ^search/search\\.asp$ search.html?zoom_query=%1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? index.php?q=%{REQUEST_URI} [L] # use this one!

If mod_rewrite is choking on the encoded characters, you could do one of two things:

  1. Create RewriteRules to remove and replace the encoded characters (after the non-www code) OR
  • RewriteRule ^(.)%3D(.)$ $1=$2 [R=301,L,NE]
  1. Specify the encoded characters in the regex within character range definitions (I know that those are translated).
  • RewriteCond %{QUERY_STRING} zoom_query=([^&\ ]) # to NOT match & or + in the query string OR
  • RewriteCond %{QUERY_STRING} zoom_query=([a-z]+) # if you’re only allowing lowercase letters

HOWEVER, if you’re going to this much trouble, I’ve got to ask about your hosting. Is this your own VPS/dedicated server? If not (even if it is), ask your host about the encoding as this seems to be a very unusual situation (forced encoding of special characters in the URI - it may be a function of the language you’re using on the server, too, if it’s not English).

Be sure to add the NE flag to you redirections (to prevent generating more encoded characters in your URIs).

If “getting there” means a bloody forehead from banging it on the keyboard (or a brick wall), I’d agree.

RewriteRule ^treatment/fut-megasessions[COLOR="#0000FF"]\\[/COLOR].asp$ megasessions.html [R=301,L[COLOR="#0000FF"],NE[/COLOR]]

What was so hard about that? I think you just about nailed it!

Regards,

DK

  1. Create RewriteRules to remove and replace the encoded characters (after the non-www code) OR
  • RewriteRule ^(.)%3D(.)$ $1=$2 [R=301,L,NE]

I’m not sure where to put this line? See code sample below

  1. Specify the encoded characters in the regex within character range definitions (I know that those are translated).
  • RewriteCond %{QUERY_STRING} zoom_query=([^&\ ]) # to NOT match & or + in the query string OR
  • RewriteCond %{QUERY_STRING} zoom_query=([a-z]+) # if you’re only allowing lowercase letters

I’ve tried both of these and no luck.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule .? http://www.newhair.com%{REQUEST_URI} [R=301,L]
#RewriteRule ^(.*)%3D(.*)$ $1=$2 [R=301,L,NE] #this breaks the site

RewriteCond %{QUERY_STRING} zoom_query=([^&\\ ]) # no luck
#RewriteCond %{QUERY_STRING} zoom_query=([a-z]+) # no luck here either
RewriteRule ^search/search\\.asp$ search.html?zoom_query=%1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

ask your host about the encoding as this seems to be a very unusual situation (forced encoding of special characters in the URI - it may be a function of the language you’re using on the server, too, if it’s not English).

Whats odd is that I believe that Google has cached/stored the links this way, which is evident in the google search results. I will ask my server. its just a regular English server running LAMP

If “getting there” means a bloody forehead from banging it on the keyboard (or a brick wall), I’d agree.

Yes Sir

RewriteRule ^treatment/fut-megasessions[COLOR="#0000FF"]\\[/COLOR].asp$ megasessions.html [R=301,L[COLOR="#0000FF"],NE[/COLOR]]

What was so hard about that? I think you just about nailed it!

This rule used to work, however I believe since taking out either “RewriteBase /” or “RewriteCond %{HTTP_HOST} .” it no longer redirects

I was just thinking, there are only 5 search words I need to redirect, is it possible to just manually write these out instead of trying to write a catchall function?

rc,

Sure! It may even pay to use mod_alias redirections (faster - they’re part of the Apache core functions) so they’ll be handled before mod_rewrite code is even parsed (the order makes no difference, core directives are always handled before mod_rewrite).

As usual, it’s always best to use the correct tool for the job.

Regards,

DK