The Entrepreneur Forum | Startups | Entrepreneurship | Starting a Business | Motivation | Success

HELP! Any regular expression experts here?

Accelerate wealth. Build a business that pays freedom. Join more than 70,000 entrepreneurs and register for the Fastlane Entrepreneur forum. Remove ads? Join the INSIDERS.

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
I've Read Rat-Race Escape!
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
32,621
124,523
3,751
Fountain Hills, AZ
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
 

Don't like ads? Remove them while supporting the forum. Subscribe.

  • Thread starter
  • Admin
  • #3

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
I've Read Rat-Race Escape!
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
32,621
124,523
3,751
Fountain Hills, AZ

ApparentHorizon

Platinum Contributor
Speedway Pass
Apr 1, 2016
944
2,794
653
Greenville, SC
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

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
 
  • Thread starter
  • Admin
  • #5

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
I've Read Rat-Race Escape!
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
32,621
124,523
3,751
Fountain Hills, AZ
I think it needs to be the other way around? The url with "general-business-etc" should be the one redirecting.
 

scottmsul

Bronze Contributor
FASTLANE INSIDER
Read Millionaire Fastlane
I've Read UNSCRIPTED
Speedway Pass
Apr 29, 2017
131
380
190
30
Boulder, CO
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.
 
  • Thread starter
  • Admin
  • #7

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
I've Read Rat-Race Escape!
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
32,621
124,523
3,751
Fountain Hills, AZ
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


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.

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.
 
  • Thread starter
  • Admin
  • #8

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
I've Read Rat-Race Escape!
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
32,621
124,523
3,751
Fountain Hills, AZ
My iteration works, but it isn't working in the htaccess file.

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]
 

Sponsored Offers

Introducing MJ's Personal Unscripted Network, Join Now for FREE!
Text from today... Muhammad Ali said, "I hated every minute of training", but followed with...
  • Sticky
MARKETPLACE NEW: The Best School for Going Fastlane (Now open for summer enrollment)
With 300+ students, the method and/or main sources of traffic don't saturate? Seems web design...
MARKETPLACE Fox Web School "Legend" Group Coaching Program 2021
Hi - I sent out some emails with the updates but I'll PM you now also, thanks. The issue is...
MARKETPLACE Not sure how to start? This free book will teach you how to build a successful web design business
Hi Fox. Starting the book and got through the introduction. Had a conversation with Andy Black...
  • Sticky
MARKETPLACE You Are One Call Away From Living Your Dream Life - LightHouse’s Accountability Program ⚡
Chris is super sharp and is aware of many facets of entrepreneurship and can help get your...

Learn Fastlane Business Skills & Get Profitable Within 30 Days...

Get Started Now

Don't like ads? Remove them while supporting the forum. Subscribe.

New Topics

Fastlane Insiders

View the forum AD FREE.
Private, unindexed content
Detailed process/execution threads
Ideas needing execution, more!

Join Fastlane Insiders.

Top Bottom