Welcome to Centmin Mod Community
Register Now

Xenforo How to properly rewrite this?

Discussion in 'Forum software usage' started by rdan, Oct 7, 2014.

Tags:
  1. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    From:
    Code:
    https://www.domain.com/search?q=12345
    To:
    Code:
    https://www.domain.com/index.php?search/search/&keywords=12345
    12345 is just a random/dynamic value.


    Is this correct @eva2000 ?
    Code:
    rewrite ^/index.php?search/search/&keywords=(.*)$ /search?q=$1 last;
    
     
    Last edited: Oct 7, 2014
  2. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    not so good with regex myself :oops:

    but can try
    Code:
    rewrite ^/index.php?search/search/&keywords=(.*)$ /search?q=$1 last;
    but probably pointless to do this as no one really pays attention to long urls these days

    even my forum search urls are short enough
    Code:
    https://community.centminmod.com/search/84862/?q=nginx&o=relevance
     
  3. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    Inside /location/ block or works on outside?
     
  4. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    Not working :(
     
  5. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    outside of location blocks use last, instead location blocks you might need to replace last with break
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    probably because your url is before custom rewrite is
    Code:
    https://www.example.net/search/794521/?q=helo&o=relevance
     
  7. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    What do you mean before?
     
  8. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    Normally this url:
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=12345
    Should return a query search for 12345.

    But I want to follow google's recommendation here: Rich Snippets - Webmaster EDU - Webmasters — Google Developers

    I want to have a short version of it:
    Code:
    https://www.phcorner.net/search?q=12345
    That will auto redirect to the original xenforo long query url and then produce a search results.
     
  9. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    oh you edited your first post above How to properly rewrite this? | Centmin Mod Community and you have the from and to reversed

    i though you want final url to be
    Code:
    https://www.phcorner.net/search?q=
    but you want it to be
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=
    which is the reverse of what you originally posted
     
  10. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    oh you edited your first post above How to properly rewrite this? | Centmin Mod Community and you have the from and to reversed

    i though you want final url to be
    Code:
    https://www.phcorner.net/search?q=
    but you want it to be
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=
    which is the reverse of what you originally posted
     
  11. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    actually your urls return
    Code:
    https://www.phcorner.net/search/794521/?q=helo&o=relevance
    not
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=12345
     
  12. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    Yes sorry about that.
    I want the short version to redirect to xenforo original long query url then produce a search results.

    (you have some buggy addon that cause the duplicate post? :D)
     
  13. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    duplicate posts probably side effect of multiple PHP-FPM pools not sure - investigating heh

    probably better to ask Xenforo devs for rich snippets support etc
     
  14. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    Yes that's the search results produce.
    And that's expected.

    So without the rewrite on XenForo this is the process.
    Instead of having the user to fill in the form for search query, I want to have some kind of direct url, that can be use to link search result.

    Default XenForo:
    1.) I want to search "helo" keyword, then the URL is this:
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=helo
    2.) Then xenforo search the database then output the search result with a temporary url which is:
    Code:
    https://www.phcorner.net/search/794568/?q=helo&o=relevance
    That url is just temporary and will expired.


    So right now I want to add the google's recommendation for search query url.
    Then is all I want:
    1.) Produce/use a short url for search/follow google's recommendation which is:
    Code:
    https://www.phcorner.net/search?q=12345
    Nginx rewrite it and change to default xenforo query url.

    2.) Preserve "helo" keyword, then the URL will be:
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=helo
    3.) Then xenforo search the database then output the search result with a temporary url which is:
    Code:
    https://www.phcorner.net/search/794568/?q=helo&o=relevance
    That url is just temporary and will expired.
     
  15. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    search result on a unique and static url not temporary is already possible, for now all I want is the rewrite form short version > to xenforo search query url :)
     
  16. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    problem is the search id (794568) is unknown and AFAIK without it, the keyword url won't work
     
  17. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    Disregard that, that's not important :D
    That specific url is dynamic.

    This is my problem :)
    1.) Produce/use a short url for search/follow google's recommendation which is:
    Code:
    https://www.phcorner.net/search?q=12345
    Then Nginx will rewrite it and change to default xenforo query url.

    2.) Preserve "helo" keyword, then the URL will be:
    Code:
    https://www.phcorner.net/index.php?search/search/&keywords=helo
     
  18. eva2000

    eva2000 Administrator Staff Member

    53,811
    12,159
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,711
    Local Time:
    5:09 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    oh i see what you want
    Code:
    rewrite ^/search?q=(.*)$ /index.php?search/search/&keywords=$1 last;
     
  19. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2
    It's the reverse I think hehehe
    Example on this forum, Someone need help about nginx.
    And you want to forward him the search result for that keyword, so you will give this link to that person:
    Code:
    https://community.centminmod.com/index.php?search/search/&keywords=Nginx
    Normally it will work just very fine.

    But again, hehe I want to have the google suggested url.
    So will give this short url to someone:
    Code:
    https://community.centminmod.com/search?q=Nginx
    Then the user follow that link.
    Then your Nginx server rewrite it to:
    Code:
    https://community.centminmod.com/index.php?search/search/&keywords=Nginx
    Then search result again will show up. :)
     
  20. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    3:09 AM
    Mainline
    10.2