0

I can't seem to get my regex working properly.

This works fine:

RewriteRule ^profile/([0-9]+)/?$ profile.php?customURL=$1 [NC,L]

But there's some mistakes. For one, the $1 is alphanumeric, not just numbers (it still works, though). Also, I don't want profile/ in the URL anymore.

I tried this:

RewriteRule ^(/^\w+$/)/?$ profile.php?customURL=$1 [NC,L]

But it didn't work at all. What am I doing wrong?

1 Answer 1

2

It looks like you're trying to embed a regex inside another? I don't think that works. Try this:

RewriteRule ^(\w+)/?$ profile.php?customURL=$1 [NC,L]

We select 1 or more word characters from the start of the string to the end, optionally terminated by a /.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thanks a lot. I should really do another regex tutorial, but this is the only one I need in my current project, and I'm up to my armpits in APIs!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.