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

HELP! Any regular expression experts here?

Remove ads while supporting the Unscripted philosophy...become an INSIDER.

  • Thread starter
  • Admin
  • #1

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
30,702
112,804
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
OP
OP
M

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
30,702
112,804
3,751
Fountain Hills, AZ

ApparentHorizon

Platinum Contributor
Speedway Pass
Apr 1, 2016
945
2,772
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
OP
OP
M

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
30,702
112,804
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
364
190
29
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
OP
OP
M

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
30,702
112,804
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
OP
OP
M

MJ DeMarco

Administrator
Staff member
EPIC CONTRIBUTOR
FASTLANE INSIDER
Read Millionaire Fastlane
I've Read UNSCRIPTED
Summit Attendee
Speedway Pass
Jul 23, 2007
30,702
112,804
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]
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Sponsored Offers

  • Sticky
MARKETPLACE Lex DeVille's - Advanced Freelance Udemy Courses!
Great. I will check them out and share my feedback. Thanks for sharing and helping us with your...
  • Sticky
MARKETPLACE You Are One Call Away From Living Your Dream Life - LightHouse’s Accountability Program ⚡
Was talking to @Vigilante yesterday and he suggested I try a new media to put out some of the...
  • Sticky
MARKETPLACE Fox' Web School's "Legend" Group Coaching Program 2020
This year has been quite crazy so far, and a lot of people have reached out to ask me if web...
  • Sticky
FEATURED! Introducing... WEALTH EXPO$ED, A Short Story By MJ DeMarco
Got it several weeks ago and have listened to it several times now. I've definitely met both...
  • Sticky
MARKETPLACE Kill Bigger Incubator
@Kak Out of curiosity, what types of businesses are you advising on? (I read this whole thread...
  • Sticky
MARKETPLACE Grow Your Business With a Book (An Unorthodox Marketing Strategy That Built One of the Largest...
Thanks for your offer to look at my book. Here's the link to the squeeze page Buy The Prosperous...



Forum Sponsor

sponsor

New Topics

Fastlane Insiders

View the forum AD FREE.
Private, unindexed content
Detailed process/execution threads
Monthly conference calls with doers
Ideas needing execution, more!

Join Fastlane Insiders.

Top Bottom