1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Buying WP url fix

Discussion in 'Programming' started by mads, Sep 16, 2016.

  1. #1
    Have a standard WP page that works as a search page for some custom data (data from tables that are outside WP).

    Currently the url is like this "/search/?q=[query]". For example "/search/?q=digital-point".

    We need help change the url structure to "/search/[query]". For example "/search/digital-point/".

    Note that the search isn't related to standard WP search. The query is handled completely by the /search/ page.

    PM if this is something you can do.

    Include your price and turnaround time (I assume you can fix this by sending us some code to paste into the child theme functions.php).

    Thanks,
    Mads
     
    mads, Sep 16, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    This is fixed by adding a couple lines into .htaccess

    Not functions.php

    On my phone, so can't provide code, but it should take less than 5 minutes
     
    PoPSiCLe, Sep 16, 2016 IP
  3. mads

    mads Well-Known Member

    Messages:
    762
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #3
    Wish you were not on you phone then :)

    Feel free to PM when you are in front of the computer (I assume the .htaccess fix will only affect the /search/ page and not all the other pages/posts).
     
    mads, Sep 16, 2016 IP
  4. mads

    mads Well-Known Member

    Messages:
    762
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #4
    We are soon moving to an nginx based VPS, so a .htaccess solution might not be the best approach (since nginx doesn't use .htaccess files).

    Because of nginx, we prefer a code block we can paste into our child theme functions.php
     
    mads, Sep 16, 2016 IP
  5. Ajeet Singh

    Ajeet Singh Active Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Hi Mads,
    You can fix it yourself in WP, in login panel you have a permalink option from there set your url as you require. Not needed to pay for that which you can fix yourself in seconds.
     
    Ajeet Singh, Sep 16, 2016 IP
  6. mads

    mads Well-Known Member

    Messages:
    762
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #6
    This is not standard WP functionality, so it cannot be set via permalinks.
     
    mads, Sep 16, 2016 IP
  7. Ajeet Singh

    Ajeet Singh Active Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    Can you please PM the URL so that I can check and give you solution.
     
    Ajeet Singh, Sep 16, 2016 IP
  8. Ajeet Singh

    Ajeet Singh Active Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    Please let me know if you have used wp_redirect and still did not get solution?


    function fb_change_search_url_rewrite(){if( is_search()&&! empty( $_GET['s'])){
    wp_redirect( home_url("/search/"). urlencode( get_query_var('s')));exit();}}
    add_action('template_redirect','fb_change_search_url_rewrite');
     
    Ajeet Singh, Sep 16, 2016 IP
  9. Ajeet Singh

    Ajeet Singh Active Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    It is also possible via htacces rules, but the source is an example for custom solutions on an redirect.
    RewriteCond%{QUERY_STRING} \\?s=([^&]+)[NC]
    RewriteRule^$ /search/%1/?[NC,R,L]
     
    Ajeet Singh, Sep 16, 2016 IP
  10. Ajeet Singh

    Ajeet Singh Active Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #10
    There are many other ways to customize your search URL. I hope you will get solution from it.
     
    Ajeet Singh, Sep 16, 2016 IP
  11. mads

    mads Well-Known Member

    Messages:
    762
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #11
    Thanks a lot for the code.

    It's not a WP search, so it's not caught by is_search() + there is no query_var "s".

    I can catch that we are on the /search/ page like this: if(strpos(get_permalink(), "/search/") !== false)

    Problem is that we don't stay on the /search/query/ page. Instead things are automatically redirected to the closest match by something in WP.
     
    mads, Sep 17, 2016 IP
  12. Ajeet Singh

    Ajeet Singh Active Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #12
    Can you please share that website URL to check and understand the issue?
     
    Ajeet Singh, Sep 17, 2016 IP
  13. mads

    mads Well-Known Member

    Messages:
    762
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #13
    Please send a PM with your email and I'll send you some more details.
     
    mads, Sep 17, 2016 IP