Modrewrite redirect old search variables?

I’m having a bit of a problem. For a recent project I recently converted all the content on a .asp website to MODX and they had a Google search. Google has indexed their page “search.asp” and it is appearing in searches on the new site. The first link works properly, but the second link on the following page is linking to /search/search.asp and is just redirecting to the homepage by default. Here: http://www.newhair.com/search.html?zoom_query=steve+hartman. I need to get rid of this “search.asp” page!

I’m trying to use mod rewrite to redirect the old .asp search page to the new page but its not working.

RewriteRule ^search/search\.asp$ search.html [R=301,L]

Basically I want to redirect this old page (with the search variable “steve”):
http://www.newhair.com/search/search.asp%3Fzoom_query%3Dsteve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0

To this new page (with the same search variable “steve”):
http://www.newhair.com/search.html?zoom_query=steve

Any ideas?

Here is my full .htaccess file:


# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
RewriteBase /



# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]



# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]

RewriteRule ^search/search\\.asp$ search.html [R=301,L]


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



# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off



# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary

As an alternative, is it possible to have search.asp go to throw a 404 error so google ignores it and removes it from their cache altogether?

rc,

Aw, you know to wrap your code in [noparse]

 ... 

[/noparse] wrappers! Ditto whatever you were using to indent. Both disappear in the quote reply here!

Okay, the first problem you’re having is that your query string has a LOT of other @#$* in it after the zoom_query=steve. If you do nothing about the query string, it’ll all be passed and your search.html (PHP?) script can ignore everything after steve (starting with the &). If you need to strip everything after steve, it’s not difficult:

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

Translated, that’s "if the URI is search/search.asp and the query string starts with zoom_query=something then redirect to search.html with the NEW query string of zoom_query=something AND make the redirection permanent.


# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
[COLOR="#FF0000"]RewriteBase /[/COLOR]
# Not necessary


# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#

[COLOR="#FF0000"]# RewriteCond %{HTTP_HOST} .[/COLOR]
# Not needed
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
[COLOR="#FF0000"]# RewriteRule (.*) http://www.newhair.com/$1 [R=301,L][/COLOR]
# I prefer
RewriteRule .? http://www.newhair.com%{REQUEST_URI} [R=301,L]


# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]

RewriteRule ^search/search\\.asp$ search.html [R=301,L]


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



# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off
[COLOR="#0000FF"]# I think you DO want these OFF![/COLOR]


# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary 

Of course, but why when the problems solved above? Better to tell Google (and other SE’s) that you’ve relocated the files so you retain PR.

Redirect 410 search/search.asp /404.php

Code 410 is Gone which should certainly remove search/search.asp from all SE’s.

Regards,

DK

rc,

Still not working?

Removing the debris from your .htaccess code:

# Initialize mod_rewrite
RewriteEngine On

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

# redirect from search/search.asp to search.html
RewriteRule ^search/search\\.asp$ search.html [R=301,L]

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

The only thing that can go wrong (on an Apache server with mod_rewrite enabled and .htaccess as the per directory file - server settings along with Options FollowSymLinks and AllowOverride All) is that search.html does not exist in the DocumentRoot (fails the !-f test). Since I know you’re smarter than that, I’ve got to assume an IIS or mod_rewrite is not enabled (try the test in my signature’s tutorial) or MODX is ???

Regards,

DK

Still working on it David… will follow up tonight

Ok David, I tried your code for the search.asp in both examples (unsuccessfully) and I think the best method is to have Google hit the 404 page to just uncache search.asp.

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

One question, should I create a 404.php page to make it “nicer”? Will Google still be able to uncache it?

rc,

The 410 is being reported so you’re using something in your NEW .htaccess which is working. mod_rewrite, I presume?

Please show your new code so we can get to the bottom of this.

The Apache message for the 410 is quite clear … but it’s nothing that you should want to display to anyone. IMHO, a 404.php script and a 410.php script would be in order … but don’t give up just yet!

Regards,

DK

the 404 is working perfectly. That 404 error page must be an apache default page. My question for you is if its okay to put a more user friendly 404.php page without interfering with Google and trying to uncache search.asp.

I set up this html page that ideally it would be best to forward all 404 errors to (including search/search.asp), but as long as it wont interfere with Google uncaching the old search/search.asp page:
http://www.newhair.com/404.html

Here is my .htaccess file

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]

RewriteRule ^search/search.asp 404.php [R=410,L]

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

That search line is actually:

RewriteRule ^search/search.asp 404.html [R=410,L]

However, the server is still defaulting to the apache 404 page instead of 404.html (aka http://www.newhair.com/404.html)

Same rewrite problem again with the search variables… har har har… : /

rc,

I hope you’re meaning the 410 error page as that’s what I was seeing.

YES, indeed, it’s far better to include your own ErrorDocument scripts as the default tells what’s happened but offers no way to recover (except hitting the BACK button).

Don’t worry about Google so long as you get this working ASAP.

RewriteEngine On
[COLOR="#FF0000"]RewriteBase /[/COLOR]
[COLOR="#0000FF"]# If this is your entire .htaccess, you clearly don't need a RewriteBase statement[/COLOR]

[COLOR="#FF0000"]RewriteCond %{HTTP_HOST} .[/COLOR]
[COLOR="#0000FF"]# You don't need this either - unless your server doesn't know the domain which is, er, impossible?[/COLOR]
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]

RewriteRule ^search/search.asp 404.php [R=410,L]
[COLOR="#0000FF"]# If it'll redirect to the 404 script, it'll redirect to the search.html script (IF it exists). I'd use:
# RewriteRule ^search/search\\.asp$ search.html [R=301,L][/COLOR]

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

No matter about the 404.html or 404.php so long as Apache will server the @#$% thing!

That means that Apache’s attempted to find the 404.html file, failed and delivered its default page instead ('cause it couldn’t fine 404.html).

The search variables in the original URL? Unless you add a query string OR kill a query string, the query string will be passed through unharmed. Your use of QSA will retain the original query string while adding q={requested URI}.

Without confirmation from you, I’m not fully convinced you’re on an Apache server or tested (see the test in the tutorial linked in my signature) to verify that mod_rewrite is enabled and working properly. It should be enabled if your .htaccess is being parsed by Apache and not throwing 500 errors but, if you’re on a WinDoze server, it’s likely not even looking at .htaccess (Wyatt, wwb_99, can correct me on that if he’s around). Since your reports indicate something drastically wrong, I really NEED these confirmations (because the code is correct and there’s no excuse for not seeing the redirection IF THIS IS ALL YOU HAVE IN .htaccess IN YOUR DocumentRoot)!

Regards,

DK

David,

Yes Im running a GoDaddy virtual dedicated server running LAMP.

What do you think about this:
The old web design had a right column that listed a few featured links, and one of those links was to the “Steve Hartman” page. This link appeared on nearly every page, and so Google has cached it, which is why you see all those extra results when you search for Steve Hartman. These search results aren’t links to pages about Steve Hartman at all. Technically if I redirected them to the original page they were pointing to, there would be nothing on the page about Steve. This is why I’m considering doing a permanent 404 error or whatever it takes to have Google uncache it so any URL that matches “search/search.asp?variable=123” will stop appearing in all my searches.

I tried you code above to try and point to the 404.html page, however Im not sure why its still going to the Apache default page. I am reverting back to trying your code to get the search results redirected to the new page and im getting the same result. It redirects to the homepage by default.

My head is really starting to spin on this, I really appreciate your time Sir.

Here is my current .htaccess file:



# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
#RewriteBase /



# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#

#RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]



# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]

RewriteRule ^search/search\\.asp$ search.html [R=301,L]
#RewriteRule ^search/search\\.asp /404.html [R=410,L]


RewriteCond %{QUERY_STRING} ^pt=(ao|az|bf|bi|cc|cf|ck|ec|ec2|ej|es|fc|fc2|gc|gi|go|gq|iz|jq|ki|lf|lk|ll|ml|oi|ql|qq|rd|rf|si|uq|zu|aq|as|bi|cz|is|jg|jh|ji|kl|kq|le|lz|oi|qb|qi|ri|sz|ul|vi|vq|zo|bf|jq|li|or|wr|bg|rq|uk|ll|ru|mja|mjb|ai|aq|av|ba|bl|cq|cq2|ei|ek|eq|fi|fr|gf|gi|gr|hl|if|iq|is|jd|jq|jq2|ki|ko|lb|lc|lc2|lj|lr|lu|ma|ni|od|oj|qa|qi|qk|qo|qs|ri|ri2|rm|rq|su|vg|vs|vv|xg|xw|zf|ng|ds|bb|nh|vt|nk|gg|sk|et|cl|at|dk|us|cs|dd|hq|kg|ok|gk|mu|lx|dl|sq|dm|qt|cm|bn|bt|df|mt|xl|xk|tm|vl|cb|gn|dn|gb|qe|sv|nq|cd|xj|td|ik|be|kb|kk|lt|lv|mn|no|ts|cg|db|dt|ee|ef|eu|ft|ic|iu|mj|de|en|nn|ws|mk|xma|th|mc|do|tv|it|dp|ct|tt|ks|ns|tw|tu|dq|nf|ce|aj|uo|eo|el|nt|xs|gp|iv|ktb|eb|nu|tx|ir|te|tl|ch|qf|lg|kp|nj|nl|ci|ld|np|tg|ou|gs|tda|ttc|tn|tc|tuh|sc|oh|os|on|nqb|nkb|nx|ms|me|lbb|lxb|ikc|eja|ekc|efw|dla|du|ctb|cx|xea|cca|cna|cea|ceb|bfa|tta|uh|zl|ze|tlb|hka|bba|kda|dia|kga|sfa|fla|tla|hna|ita|kla|klb|nua|qsa|hta|qla|cqa|itb|kqa|tba|gla|ola|joe|nna|kta|nxa|nsa|hwa|ssa|nxb|bbb|tlc|ena|sda|msa|ktc|kdb|tca|cka|kca|mst|olb|bta|eka|bpa|dta|tma|nta|ebb|esa|tcb|eca|enb|nea|ima|nia|mua|kma|kib|kfa)$

RewriteRule ^next/full-face-photos\\.asp$ patient-%1.html [R=301,L]







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



# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off



# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary


rc,

Whew! I believe that we found a couple of problems for you to correct and test.

No more spinning, if you please! :smiley:

Regards,

DK

For the time being, I’d like to focus on just the search/search.asp rewrite condition as its the most pressing. :slight_smile:

Aw, you know better than that! You will NEVER be able to match a URI AND a query string in a RewriteRule! RewriteRules can only examine the {REQUEST_URI} string; you must use a RewriteCond %{QUERY_STRING} variable=123 (or whatever you think you need to match in the query string).

So something like this for the search?

RewriteCond %{QUERY_STRING} ^zoom_query=([-a-zA-Z\\+\\ ]+)$
RewriteRule ^search/search.\\.asp$ search.html?Q=%1 [R=301,L]

rc,

Well, I like the specificity of your query string value’s regex (except escaping the +) but, if zoom_query isn’t the only key in the query string, I’d merely use zoom_query=([^&]) and leave the start and end anchors off. If it’s the only key/value pair, by all means, keep both anchors (specificity)!

Whoops, you’ve got an extra dot character in your rule. Use:

RewriteCond %{QUERY_STRING} [COLOR="#808080"]^[/COLOR]zoom_query=([^&]+)[COLOR="#808080"]$[/COLOR]
RewriteRule ^search/search\\.asp$ search.html?Q=%1 [R=301,L]

BTW, wasn’t that “Q” a “q” in prior posts? Check that before testing.

Regards,

DK

Yes thanks, the new variable in the code should be zoom_query not Q. I copied it from an older post in the other thread.

To recap, here is the link we are trying to redirect:
http://www.newhair.com/search/search.asp%3Fzoom_query%3Dsteve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0

I’ve taken the code you’ve posted and updated my .htaccess. For simplicity sake and to omit any character limit errors, I’ve removed all of the other redirects to other pages, as these are not the issue. Here is my new .htaccess file, that is still not working (not your fault :slight_smile: I really appreciate the help). Ive restarted the server with the new .htaccess file and no luck, as the above link is not redirecting as it should. Ive even tried to edit the url to “search.asp?zoom_query=steve” and it wont redirect still. Wasnt sure if it was a url encode issue.

Here is my .htaccess:



# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
#RewriteBase /

# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#

#RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]

# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]

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

#RewriteRule ^search/search\\.asp$ search.html [R=301,L]
#RewriteRule ^search/search\\.asp /404.html [R=410,L]

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

# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off



# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary


rc,

Okay, new key is zoom_query, too. Let me get rid of the debris in your .htaccess so I can see the active code more easily:

RewriteEngine On

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

# redirect search/search.asp?zoom_query={something} to search.html with the same key/value pair
# while deleting the remainder of the query string
[COLOR="#0000FF"]RewriteCond %{QUERY_STRING} zoom_query=([^&])
# this was MIA in your code[/COLOR]
RewriteRule ^search/search\\.asp$ search.html?zoom_query=%1 [R=301,L]

# The Friendly URLs part
# this will redirect EVERYTHING which is not a file or directory, i.e.,
# search.html had better exist at the DocumentRoot where this .htaccess resides
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,[COLOR="#808080"]QSA]
# I'm not sure that QSA is appropriate here[/COLOR]
[COLOR="#0000FF"]# could also have the same "don't capture what already exists" treatment, i.e.,
# RewriteRule .? index.php?q=%{REQUEST_URI} [L][/COLOR]

Now, if it’s not working, it IS my fault with the few exceptions I’ve noted in your code (after stripping all the extraneous comments). I believe that the MIA (Missing In Action) RewriteCond is the cause of the search redirection not working but the R=301 will confirm that for us.

The q in the redirection to index.php isn’t in question, is it?

Finally, I’m a bit up tight about not creating Apache variables needlessly. That’s why I keep changing your ^(.*)$ to .? and allowing the %{REQUEST_URI} variable to replace the $1 (because it already exists). I’ve done this in two places but, as it’s your code, use what you’re more comfortable with.

Regards,

DK

I tried your new code above and did some testing the the URL variables in my browser. I noticed that it was inserting the server root path in the URL

Because of that weird redirect where its adding “/var/www/vhosts/newhair.com/httpdocs/” to the URL, I’ve seen this behavior before in my testing with you and its either because “RewriteBase /” or “RewriteCond %{HTTP_HOST} .” was missing.

Just as a test, Ive added these two lines back and now when I modify the url to properly put in “?” and “=” into the URL, it redirects to search.
http://www.newhair.com/search/search.asp?zoom_query=steve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0

So two issues to work out:

  1. how can we make the rewrite rule substitute “%3F” and “%3D” for “?” and “=” in the URL respectively?
  2. The rewrite is only taking the first letter of “steve” with it, ie the url is now “zoom_query=s” instead of “zoom_query=steve”
RewriteEngine On
RewriteBase /

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

# redirect search/search.asp?zoom_query={something} to search.html with the same key/value pair
# while deleting the remainder of the query string
RewriteCond %{QUERY_STRING} zoom_query=([^&])
# this was MIA in your code
RewriteRule ^search/search\\.asp$ search.html?zoom_query=%1 [R=301,L]

# The Friendly URLs part
# this will redirect EVERYTHING which is not a file or directory, i.e.,
# search.html had better exist at the DocumentRoot where this .htaccess resides
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# I'm not sure that QSA is appropriate here
# could also have the same "don't capture what already exists" treatment, i.e.,
# RewriteRule .? index.php?q=%{REQUEST_URI} [L]

Should we tweak the rewrite so that:
search.asp%3Fzoom_query%3Dsteve

is rewritten to
search.asp?zoom_query=steve

Not sure why Google has url encoded the link variables. This could be one issue. The other issue is why its redirecting to the server root in this case, while other rewrites we’ve created are redirecting properly to the http root.

Progress!

rc,

If Apache is inserting the server path, it needs to be restarted.

The reason that the server path is inserted is that Apache first looks to the server’s root for relative redirections THEN to your domain’s DocumentRoot attempting to match the URI. It should NOT be inserting the path to the DocumentRoot in the URI so that’s where the restart comes in. It has nothing to do with either RewriteBase (designed to UNDO a mod_alias redirection so mod_rewrite can work on the URI) or {HTTP_HOST} variable.

I’m a bit concerned that your server is escaping valid characters in the URI. Perhaps an NE flag would resolve this nonsense?

# ARGH! Repeating repetitively ...

RewriteEngine On
# RewriteBase / FORGET THIS!

# force www.
# RewriteCond %{HTTP_HOST} . DITTO! This does NOTHING but ensure that there is a server variable - don't you have that in your server's configuration file?
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule .? http://www.newhair.com%{REQUEST_URI} [R=301,L]

# redirect search/search.asp?zoom_query={something} to search.html with the same key/value pair
# while deleting the remainder of the query string
RewriteCond %{QUERY_STRING} zoom_query=([^&])
# this was MIA in your code
RewriteRule ^search/search\\.asp$ search.html?zoom_query=%1 [R=301,L]

# The Friendly URLs part
# this will redirect EVERYTHING which is not a file or directory, i.e.,
# search.html had better exist at the DocumentRoot where this .htaccess resides
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# I'm not sure that QSA is appropriate here
# could also have the same "don't capture what already exists" treatment, i.e.,
# RewriteRule .? index.php?q=%{REQUEST_URI} [L]

The escaped characters should not be in your URI, however, they’ll not cause any problems as Apache knows what those character are and makes that translation automatically. However, if you’re concerned, add the CHARACTER in a character range definition (spaces must be escaped). The server path was addressed above.

Regards,

DK

I’ve restarted apache and i am using your exact code from above in the .htaccess file and it is still redirecting to server paths:
http://www.newhair.com/search/search.asp?zoom_query=hairline%26zoom_page%3D31%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0

Whats a NE flag?

Well Apache is not recognizing the characters as Google has cached them which is proven when I modified the url to add ? and =. is the character in a character range definition? I cant seem to find any examples online.

rc,

mod_rewrite’s NE flag is No Escape:

Okay, I think I see MY problem! I doubt that ? is allowed in a character range definition so please try escaping those characters with a \ in the character range definitions.

Regards,

DK

So like this?

RewriteEngine On
# RewriteBase / FORGET THIS!

# force www.
# RewriteCond %{HTTP_HOST} . DITTO! This does NOTHING but ensure that there is a server variable - don't you have that in your server's configuration file?
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule .[COLOR="#FF0000"][B]\\[/B][/COLOR]? http://www.newhair.com%{REQUEST_URI} [R=301,L]

# redirect search/search.asp?zoom_query={something} to search.html with the same key/value pair
# while deleting the remainder of the query string
RewriteCond %{QUERY_STRING} zoom_query=([^&])
# this was MIA in your code
RewriteRule ^search/search\\.asp$ search.html?zoom_query=%1 [R=301,L,[COLOR="#FF0000"][B]NE[/B][/COLOR]]

# The Friendly URLs part
# this will redirect EVERYTHING which is not a file or directory, i.e.,
# search.html had better exist at the DocumentRoot where this .htaccess resides
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# I'm not sure that QSA is appropriate here
# could also have the same "don't capture what already exists" treatment, i.e.,
# RewriteRule .? index.php?q=%{REQUEST_URI} [L]