20i Domains

Anyone good with regex / rewrites ?

Discussion in 'Scripts and Coding' started by Adam H, May 18, 2017.

  1. Adam H

    Adam H Well-Known Member Exclusive Member

    Joined:
    May 2014
    Posts:
    1,639
    Likes Received:
    231
    Im trying to do is change a format of member page URL but have tried a couple of things now and im confusing myself, could do with a fresh pair of eyes if possible

    Currently the URL's look like this :

    https://www.domain.com/members/randomusername-u101252.html

    So the base URL is /members/ , then username, then -u followed by the actual user ID.

    Id like to strip everything but the ID so it would look like:

    https://www.domain.com/members/101252/

    Something like this i guess

    RewriteRule ^members/([^\.]+)\.html$ /members/$1 [R=301,L]

    But the above only removes the .html from the end and not everything else.

    Any help would be grand :)
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
    articles.co.uk
     
  3. Edwin

    Edwin Well-Known Member

    Joined:
    Apr 2005
    Posts:
    9,954
    Likes Received:
    596
    Can the username theoretically contain "-u" within it?

    And are all the member IDs always going to be exactly 6 digits, and directly followed by ".html"?
     
  4. RobM

    RobM Retired Member

    Joined:
    Mar 2012
    Posts:
    3,289
    Likes Received:
    470
    RewriteRule ^members/(.*)-u(.*).html$ /members/$2/ [R=301,L]
     
    • Winner Winner x 2
    • Informative Informative x 1
  5. Adam H

    Adam H Well-Known Member Exclusive Member

    Joined:
    May 2014
    Posts:
    1,639
    Likes Received:
    231
    @RobM , Hero thank you. thats actually alot simpler than I thought it was going to be :D.

    Thanks for the reply Edwin, Robs answer got it.
     
  6. Edwin

    Edwin Well-Known Member

    Joined:
    Apr 2005
    Posts:
    9,954
    Likes Received:
    596
    No problem. I can't figure out whether his will break if the username happens to contain "-u" but I'm sure you can test for that easily enough.
     
  7. Adam H

    Adam H Well-Known Member Exclusive Member

    Joined:
    May 2014
    Posts:
    1,639
    Likes Received:
    231
    It should be ok in this instance but I get what your saying :) We are just rewriting from an old system and redirecting to the new one, so someone lands on

    members/randomusername-u101252.html

    They are redirected to the new structure

    members/101252/

    So the username isnt actually used at all on the new setup at all , I just needed the ID's to match as a form of redirecting as the user id's are the same on both new and old.

    Its working as it should so I'm happy :)
     
  8. Admin

    Admin Administrator Staff Member

    Joined:
    Jun 2004
    Posts:
    10,980
    Likes Received:
    378
    Sometimes this forum just rocks.