SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rewrite- redirect search result

    At least I've again studies http://datakoncepts.com/seo and tried before posting ..

    GOAL:
    redirect

    http://67.225.255.100/~soffiaw5/blog...H+SOFFIA+WARDY

    to

    http://67.225.255.100/~soffiaw5/blog/?s=Soffia+Wardy

    the closest I could get (which does NOT work):

    Code:
    RewriteCond %{QUERY_STRING} uniquekey=SEARCH+SOFFIA+WARDY
    RewriteRule ^http://67.225.255.100/~soffiaw5/blog/?s=Soffia+Wardy$ /~soffiaw5/blog/?s=$1 [QSA,L]
    PURPOSE:
    Search Results: Soffia Wardy instead the current Search Results: SEARCH SOFFIA WARDY when somebody clicks onto GO without entering any search term.
    however SEARCH SOFFIA WARDY shall remain in the search text-box.

    Hopefully somebody can relieve me - my eyes hurt and I'm tired ..

    THANK YOU !

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

    From yhour code, it looks like you missed the point that a RewriteRule can only access the {REQUEST_URI} - everything from the ? on belongs to the {QUERY_STRING}. so, if

    then you must deal with the {QUERY_STRING} via RewriteCond statements (as you've tried - but without removing the query string from the RewriteRule). Therefore, delete the portion in red and your code should work:

    Code:
    RewriteCond %{QUERY_STRING} uniquekey=SEARCH+SOFFIA+WARDY
    RewriteRule ^http://67.225.255.100/~soffiaw5/blog/?s=Soffia+Wardy$ /~soffiaw5/blog/?s=$1 [QSA,L]
    PURPOSE:
    Search Results: Soffia Wardy instead the current Search Results: SEARCH SOFFIA WARDY when somebody clicks onto GO without entering any search term.
    however SEARCH SOFFIA WARDY shall remain in the search text-box.
    If that's the REAL problem, you should disable the Submit button for as long as "SEARCH SOFFIA WARDY" remains the value for the ... uniquekey or 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
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you David for your reply. However,
    Code:
    RewriteCond %{QUERY_STRING} uniquekey=SEARCH+SOFFIA+WARDY
    RewriteRule ^http://67.225.255.100/~soffiaw5/blog/$ /~soffiaw5/blog/?s=$1 [QSA,L]
    does not deliver the desired functionality.

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /~soffiaw5/blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /~soffiaw5/blog/index.php [L]
    RewriteCond %{QUERY_STRING} uniquekey=Search+Soffia+Wardy
    RewriteRule ^http://67.225.255.100/~soffiaw5/blog/$ /~soffiaw5/blog/?s=$1 [QSA,L]
    </IfModule>
    If that's the REAL problem, you should disable the Submit button for as long as "SEARCH SOFFIA WARDY" remains the value for the ... uniquekey or s?
    I know - the search query is that much intertwined with WP code that I failed to do that w/o modifying a core WP function file, which would get overwritten on next update. All other attempts in JD & Php did not work, either.

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

    Sorry for the delay - making daily trips to the hospital keeps me busy.

    Just a quick scan of your last post, though, and I saw a couple of problems:

    1. The protocol cannot be accessed in a RewriteRule (drop the http://).

    2. The domain name cannot be accessed in a RewriteRule (drop the 67.225.255.100 - and the / if you're using an Apache 1.x server).

    3. You need to order your RewriteRule sets from most specific to the most generic, i.e., .? will always be matched and redirected to ~soffiaw5/blog/index.php so your query string will never have a chance to match anything.

    I hope that helps. I'll try to look in tomorrow night (after another late night at the hospital) to see if that resolved your problem.

    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

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,268
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    ...and the / if you're using an Apache 1.x server).
    Apache 1 and Apache 2 actually behave the same way with the leading slash. See this post where I explained in more detail.
    "First make it work. Then make it better."

  6. #6
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry to hear about the hospital trouble - hopefully the doctors and service there is superb!

    I tried all steps from above - the closest I could get was a 500 internal server error ("The request was not completed. The server met an unexpected condition.").

    Thank you for all the input - I saved your instructions in my mod-rewrite knowledge file!

    The client has by now accepted the current status so I'll do, too, and simply give up at this point.

    Be well,
    Lee

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

    Thanks for your kind words. Back from the hospital and my wife needs special care for at least 6 weeks. Healing fine, though, so we believe all's well.

    I can't believe that I left the protocol and domain in the RewriteRule after telling you that you have to remove it! Shows how I was affected.

    Without access to the httpd.conf (for a RewriteMap), you'll have to hard code your capitalization problem (or simply solve it in your receiving script - if you can).

    Code:
    RewriteCond %{QUERY_STRING} uniquekey=SEARCH+SOFFIA+WARDY
    RewriteRule ^~soffiaw5/blog/$ /~soffiaw5/blog/?s=Soffia+Wardy [L]
    You cannot have the protocol (http://) or the domain (67.225.255.100) referenced in a RewriteRule (regex). Unless you have a RewriteMap (if you do, make use of the tolower built-in function), you'll have to rewrite your query string manually. Of course, this defeats your search function so either use a dedicated (or VPS) server or make the conversion in PHP.

    If you can make use of tolower, you could use something like

    RewriteCond %{QUERY_STRING} ([A-Z]${tolower:[a-zA-Z\ ]+})

    to capitalize the first letter of the value string. I'll let you figure out how to break the query string into words and ucfirst() them with a combination of toupper and tolower if you want mod_rewrite to do the heavy lifting.

    As for your WordPress code:

    Code:
    # BEGIN WordPress
    # <IfModule mod_rewrite.c> - EVIL AND WASTEFUL!!! Test once without this then get rid of it ... FOREVER!!!
    RewriteEngine On
    RewriteBase /~soffiaw5/blog/
    # RewriteRule ^index\.php$ - [L] - that's what the !-f does for you next!
    
    # <= Insert the above code here and NEVER after WP's generic "redirect everything" code which follows.
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /~soffiaw5/blog/index.php [L] # I prefer to allow NO path/file
    
    # RewriteCond %{QUERY_STRING} uniquekey=Search+Soffia+Wardy
    # RewriteRule ^http://67.225.255.100/~soffiaw5/blog/$ /~soffiaw5/blog/?s=$1 [QSA,L]
    # The REVISED version of this needs to come before the RewriteRule set (rule & conditions) above and after the RewriteBase
    # </IfModule> - EVIL AND WASTEFUL!!!
    My sincere apologies for not having my head about me in the earlier response(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

  8. #8
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OMG, so sorry for your poor wife - I really hope she'll fully recover! In that context even more THANK YOUs for your time and efforts here!

    I applied all above code. No 500 error, but I am now sure you are right that for it to work the client would have to upgrade to a self-hosted server with access to the config file to influence the mapping, because unfortunately there is no effect --> http://67.225.255.100/~soffiaw5/blog...h+Soffia+Wardy ..

    This was a great learning experience, and I will also sure heed your tips for all future WP sites

    Blessings to you and your wife,
    Lee

  9. #9
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,268
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Is this still an issue? Seems like this should work:

    # if the query string is exactly "s=SEARCH+SOFFIA+WARDY"
    # (note that "+" is special in regexs, so we need to escape them)
    RewriteCond %{QUERY_STRING} ^s=SEARCH\+SOFFIA\+WARDY$

    # and if the path is exactly "~soffiaw5/blog/"
    # then redirect with a new query string
    RewriteRule ^~soffiaw5/blog/$ /~soffiaw5/blog/?s=Soffia+Wardy [R,L]
    "First make it work. Then make it better."

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Thank you, Lee. She's recovering amazingly quickly but a "cracked" sternum does take up to three months to mend. The bypass part of the operation seems to be trivialized by modern medicine but access makes the recovery long and involved.

    As for Jeff's escaping of the +'s, he's correct but, after testing, it will work with either an escaped + (i.e., \+) or an escaped space within a character range definition (i.e., [\ ]). As I'm always one for optimizing code, use Jeff's escaped +.

    Tip: Remember that the escaped space will work on spaces in regex where you need to match a space in the variable (e.g., {REQUEST_URI}, {THE_REQUEST} and other places where you can reasonably expect to find a space). mod_rewrite is finicky, though, as a space is used to separate the different elements of mod_rewrite statements so use care!

    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


Tags for this Thread

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
  •