Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

Anyone good with regex / rewrites ?

Joined
May 21, 2014
Posts
1,675
Reaction score
594
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 :)
 

The Rule #1

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

Premium Members

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom