• The Entrepreneur Forum | Startups | Entrepreneurship | Starting a Business | Motivation | Success
  1. The forum software will be upgraded on Sunday May 26th and may not look normal during the transition. Some functionality may be offline. This is TEMPORARY and is expected to last up to 8 hours.
  2. Join 50,000+ entrepreneurs
    who are kicking butt and
    winning their dream life.

    Unscripted™ Entrepreneurship:
    A Business That Pays More Than Money, It Pays Time.

    "Fastlane" is an entrepreneur discussion forum based on The Unscripted Entrepreneurial Framework (TUNEF) outlined in the two best-selling books by MJ DeMarco (The Millionaire Fastlane and UNSCRIPTED™). From multimillionaires to digital nomads, the forum features real entrepreneurs creating real businesses.

    Download (Unscripted) Download (Millionaire Fastlane)  Register
    Registering for the forum removes this block!

HELP! Any regular expression experts here?

Discussion in 'Education, Learning, Books' started by MJ DeMarco, Feb 5, 2019.

Tags:
  1. MJ DeMarco
    Online

    MJ DeMarco Raving Lunatic Staff Member Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass LEGENDARY CONTRIBUTOR Summit Attendee

    Messages:
    28,047
    Likes Received:
    93,365
    Joined:
    Jul 23, 2007
    Gender:
    Male
    Location:
    Phoenix, AZ
    Rep Bank:
    $404,821
    Admin Post
    Any reg-ex experts on the board? For the life of me, I can never figure out regular expressions. I'm having a URL redirect problem (for an Htaccess file) and was hoping to find a solution. I've spent a bunch of time on several websites trying to figure out the solution.

    Reg-exs have always been like Japanese to me. I tried using this tool to no avail:

    Free Online Regular Expression Tester - FreeFormatter.com

    Basically I'm looking to solve a problem a described below...

    301 Redirect

    Code:
    OLD PAGE
    -------
    https://www.thefastlaneforum.com/general-business-discussion/35110-golden-nuggets-tips-processes-how-tos.html
    
    TO THIS NEW PAGE
    -------
    https://www.thefastlaneforum.com/community/threads/golden-nuggets-tips-processes-how-tos.35110/
    
    Optimally, any link with "general-business-discussion" should redirect to "community/threads/[thread-title].[thread-number]
    
    Looking for a "catch all" for the above, not just the one link redirected.
    I know for a reg-ex expert this is easy-peezy like asking someone to translate English to Japanese. Probably is, I know no Japanese and after a few hours of trying to learn I'm no closer to the solution. I picked a bad day to have some caffeine.

    Another tool that I found helpful but still haven't got to a solution...

    Regex101 - online regex editor and debugger
     
    Xeon, YoungPadawan and Andy Black like this.
  2. Raoul Duke
    Online

    Raoul Duke Tallest Lannister Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass Summit Attendee

    Messages:
    1,341
    Likes Received:
    4,762
    Joined:
    Feb 26, 2016
    Gender:
    Male
    Rep Bank:
    $10,215
  3. MJ DeMarco
    Online

    MJ DeMarco Raving Lunatic Staff Member Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass LEGENDARY CONTRIBUTOR Summit Attendee

    Messages:
    28,047
    Likes Received:
    93,365
    Joined:
    Jul 23, 2007
    Gender:
    Male
    Location:
    Phoenix, AZ
    Rep Bank:
    $404,821
    Admin Post
    Thank you but that really doesn't help me.

    This seems to work in the RegEx101, now I got to translate it.

    Code:
    (general-business-discussion).(\d+)*.(.+)?(.html?)
    
    AND
    
    community/threads/$3.$2
     
  4. ApparentHorizon
    Offline

    ApparentHorizon Gold Contributor Speedway Pass

    Messages:
    770
    Likes Received:
    2,229
    Joined:
    Apr 1, 2016
    Location:
    Greenville, SC
    Rep Bank:
    $8,592
    Something closer to this... I haven't tested it

    Code:
    RewriteRule ^community/threads/([0-9a-zA-Z-]+).([0-9]+)/ /general-business-discussion/$1-$2.html
    
     
    MJ DeMarco likes this.
  5. MJ DeMarco
    Online

    MJ DeMarco Raving Lunatic Staff Member Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass LEGENDARY CONTRIBUTOR Summit Attendee

    Messages:
    28,047
    Likes Received:
    93,365
    Joined:
    Jul 23, 2007
    Gender:
    Male
    Location:
    Phoenix, AZ
    Rep Bank:
    $404,821
    Admin Post
    I think it needs to be the other way around? The url with "general-business-etc" should be the one redirecting.
     
  6. scottmsul
    Online

    scottmsul Bronze Contributor Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass

    Messages:
    79
    Likes Received:
    257
    Joined:
    Apr 29, 2017
    Gender:
    Male
    Location:
    Boulder, CO
    Rep Bank:
    $1,541
    There could be issues if someone creates a thread with "general-business-discussion" in the name. Maybe something like this?

    Code:
    ^https://www.thefastlaneforum.com/general-business-discussion/(\d+)-(.+)(.html)?$
    
    https://www.community/threads/$3.$2
    
    More specific is generally better. ^ and $ are usually the start and end of a string but may depend on the language.
     
    ApparentHorizon and MJ DeMarco like this.
  7. MJ DeMarco
    Online

    MJ DeMarco Raving Lunatic Staff Member Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass LEGENDARY CONTRIBUTOR Summit Attendee

    Messages:
    28,047
    Likes Received:
    93,365
    Joined:
    Jul 23, 2007
    Gender:
    Male
    Location:
    Phoenix, AZ
    Rep Bank:
    $404,821
    Admin Post

    Thank you both, much appreciated.

    Unfortunately neither work.

    Can be tested here:
    htaccess Tester - madewithlove

    My iteration works, but it isn't working in the htaccess file.
     
  8. MJ DeMarco
    Online

    MJ DeMarco Raving Lunatic Staff Member Read Millionaire Fastlane I've Read UNSCRIPTED FASTLANE INSIDER Speedway Pass LEGENDARY CONTRIBUTOR Summit Attendee

    Messages:
    28,047
    Likes Received:
    93,365
    Joined:
    Jul 23, 2007
    Gender:
    Male
    Location:
    Phoenix, AZ
    Rep Bank:
    $404,821
    Admin Post
    Got it to work finally, but as @scottmsul mentioned, it's a little sketchy.

    Code:
    RewriteRule .*(general-business-discussion).(\d+)*.(.+)?(.html?) /community/threads/$3.$2 [R=301,L]
    
     

Join 1000s of entrepreneurs who are rewriting life's script and winning financial freedom.

---- ----

You must be a member to join the conversation.

Create Account

Join the community fast and easy!

REGISTER

Log In

Already have an account? Login here.

LOG IN

Share This Page