Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. Share your own thoughts and experience, accounts may be terminated for violations.
  • Welcome to AcornDomains.co.uk, a friendly community for UK domain investors, developers and anyone interested in domain names.

    Whether you're looking to buy or sell domains, learn more about the UK domain market, get feedback on your names, or simply chat with other domainers, you're in the right place. AcornDomains has been bringing together people from across the UK domain industry for many years, from complete beginners to experienced investors.

    Have a look around, join the discussions and, if you haven't already, create a free account and introduce yourself.

Anyone good with regex / rewrites ?

Adam HAdam H is verified member.

SEO Services
Web Dev
Joined
May 21, 2014
Posts
1,699
Reaction score
623
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 :)
 
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"?
 
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"?

RewriteRule ^members/(.*)-u(.*).html$ /members/$2/ [R=301,L]

@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.
 
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.
 
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 :)
 
Top Bottom