SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?z...=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...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?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    rc,

    Aw, you know to wrap your code in [code] ... [/code] 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:
    Code:
    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.


    Code:
    # 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 /
    # 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
    #
    
    # RewriteCond %{HTTP_HOST} .
    # Not needed
    RewriteCond %{HTTP_HOST} !^www\.newhair\.com [NC]
    # RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]
    # 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
    # I think you DO want these 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
    Quote Originally Posted by rc
    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?
    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.
    Code:
    Redirect 410 search/search.asp /404.php
    Code 410 is Gone which should certainly remove search/search.asp from all SE's.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    rc,

    Still not working?

    Removing the debris from your .htaccess code:
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still working on it David... will follow up tonight

  5. #5
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...26zoom_and%3D0

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

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    Code:
    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]

  8. #8
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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... : /

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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.

    Code:
    RewriteEngine On
    RewriteBase /
    # If this is your entire .htaccess, you clearly don't need a RewriteBase statement
    
    RewriteCond %{HTTP_HOST} .
    # You don't need this either - unless your server doesn't know the domain which is, er, impossible?
    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]
    # 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]
    
    # 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!

    Quote Originally Posted by rc
    However, the server is still defaulting to the apache 404 page instead of 404.html (aka http://www.newhair.com/404.html)
    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).

    Quote Originally Posted by rc
    Same rewrite problem again with the search variables... har har har... : /
    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 K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code:
    # 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

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    rc,

    Quote Originally Posted by ripcurlksm View Post
    David,

    Yes Im running a GoDaddy virtual dedicated server running LAMP.

    Really? Have you found GoDaddy as bad as everyone says it is?

    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.

    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).

    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.

    Yes, that's because your code cannot ever match and redirect.

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

    Here is my current .htaccess file:
    Code:
    # 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]
    
    
    Fine.
    # 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]
    That's fine, too!
    #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)$
    YGBSM! I believe that Apache will stop looking after 255 characters on a line. This absurdly long "thing" is 1088 characters (with the two spaces) and cannot possibly be acceptable to Apache. If you need to test, break this up into at least 5 lines and include the [OR] flag between them (but not after the last RewriteCond statement).
    RewriteRule ^next/full-face-photos\.asp$ patient-%1.html [R=301,L]
    I trust that patient-%1.html is servable either as an html script, php script called by the .html extension or via index.php?q=patient-%1.html.
    # 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
    Whew! I believe that we found a couple of problems for you to correct and test.

    No more spinning, if you please!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  12. #12
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the time being, I'd like to focus on just the search/search.asp rewrite condition as its the most pressing.

    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?
    Code:
    RewriteCond %{QUERY_STRING} ^zoom_query=([-a-zA-Z\+\ ]+)$
    RewriteRule ^search/search.\.asp$ search.html?Q=%1 [R=301,L]

  13. #13
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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:

    Code:
    RewriteCond %{QUERY_STRING} ^zoom_query=([^&]+)$
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  14. #14
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...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 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:
    Code:
    # 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

  15. #15
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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:

    Code:
    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
    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]
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  16. #16
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...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"


    Code:
    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!

  17. #17
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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?

    Quote Originally Posted by rc
    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"
    Code:
    # 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]
    Quote Originally Posted by rc
    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!
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  18. #18
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    If Apache is inserting the server path, it needs to be restarted.

    Perhaps an NE flag would resolve this nonsense?
    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...26zoom_and%3D0

    Whats a NE flag?

    Quote Originally Posted by dklynn View Post
    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.
    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.

  19. #19
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    rc,

    mod_rewrite's NE flag is No Escape:

    Quote Originally Posted by apache.org
    'noescape|NE' (no URI escaping of output)
    This flag prevents mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from happening.
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  20. #20
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So like this?

    Code:
    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,NE]
    
    # 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]

  21. #21
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by ripcurlksm View Post
    So like this?

    Code:
    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] # \ removed from regex
    
    # 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,NE] # yes
    
    # 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] # use this one!
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  22. #22
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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):

    Code:
    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:
    Code:
    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" :
    Code:
    http://www.newhair.com/var/www/vhosts/newhair.com/httpdocs/search.html?zoom_query=s
    Getting there!

  23. #23
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

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

  24. #24
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,679
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    rc,

    Code:
    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]
    • ...


    2. 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.

    Code:
    RewriteRule ^treatment/fut-megasessions\.asp$ megasessions.html [R=301,L,NE]
    What was so hard about that? I think you just about nailed it!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  25. #25
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    2. 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.

    Code:
    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

    Code:
    RewriteRule ^treatment/fut-megasessions\.asp$ megasessions.html [R=301,L,NE]
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •