Vanity URL issue

currently my vanity url works with…

RewriteRule ^(.*)$ …/profile.php?u=$1 [NC]

Once a user registers their vanity url is mydomain.com/username

I want to change the structure to

RewriteRule ^(.*)$ …/u/profile.php?u=$1 [NC]

but this continually breaks. I’d like to have users sign in to

mydomain.com/u/username

If you want to change the URL you need to change the first part of the RewriteRule, not the second part. The second part is to indicate what file should actually be loaded, and that didn’t change, right?

So, to change your example, it would be:


RewriteRule ^u/(.*)$ ../profile.php?u=$1 [NC]

Two remarks about that code though:

  1. The [NC] at the end is to indicate you want to perform the regular expression in a case insensitive manner, but since (.*) will already eat up anything and everything it sees regardless of the case you can drop that [NC] at the end.
  2. Unless there are more rules in the .htaccess that take the URL …/profile.php?u=$1 as input, you need to add a [L] flag to the Rewrite to prevent apache from burning CPU cycles for nothing.

So, with those two comments in mind, the new rule would be:


RewriteRule ^u/(.*)$ ../profile.php?u=$1 [L]

That seemed to destroy my site. Any other suggestions on how to make this work?

What broke? Didn’t it do what you wanted it to do or did you get an internal server error?

Also, you know the rule only cause /u/<username> to work, right?
Any links pointing to /<username> need to be changed to /u/<username> by you; that’s nothing Apache can do for you.

I had an internal server error. I know that my links need to be changed :slight_smile:

I’ll be able to give this another shot in about 2 hours.

Are you on Apache 1.x or 2.x ?

If you’re on 1.x the rule should be :


RewriteRule ^/u/(.*)$ ../profile.php?u=$1 [L]

on 2.x it should be:


RewriteRule ^u/(.*)$ ../profile.php?u=$1 [L]

Or, if you’re not sure you can do this:


RewriteRule ^/?u/(.*)$ ../profile.php?u=$1 [L]

I don’t see why that won’t work. Unless …/profile.php doesn’t exist. Since you had a rule that also used …/profile.php that won’t be the problem.
Let me know how you get on :slight_smile:

I think the problem is with the redirection. What is … supposed to mean, going one directory level UP from the DocumentRoot? It can’t be done! PUT the .htaccess in the DocumentRoot and leave the …/ off the redirection.

un, whereever did you get that code?

Regards,

DK

Thank you very much for solving my issue! It worked out great. I just had to play with it a little bit.