Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

Anyone good with regex / rewrites ?

Joined
May 21, 2014
Posts
1,725
Reaction score
603
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 :)
 
Sometimes this forum just rocks.
 

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom