How can I use more than ONE vanity URL?

105 Views Asked by At

So I already have a vanity URL on my site for average users profiles...

basecentre.co.uk/user1

this redirects users to

basecentre.co.uk/userprofile.php?username=user1

using the code below...

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{QUERY_STRING} ^thankyou-page=([0-9]*)$ 
RewriteRule ^(.*)$ affilates_redirect.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /userprofile.php?username=$1
RewriteCond %{HTTP_HOST} ^www.basecentre.co.uk$ [NC]
RewriteRule ^(.*)$ http://basecentre.co.uk/$1 [R=301,L]
</IfModule>

I am trying to create business profiles too, and was looking to do the same sort of thing but using a different page on my site so say...

basecentre.co.uk/businessprofile.php?businessname=mcdonalds

would become

basecentre.co.uk/mcdonalds

And it wouldn't get confussed with the normal user profiles. Would this work or can you only have ONE vanity URL on your site? If that is true, is there any other option I could use?

Also if this is possible, if you have a username with the same business profile name what would happen?

Thanks for the help!

2

There are 2 best solutions below

2
On

I would recommend to use URL schemes like /user/user1 and /business/macdonalds. This will exclude any collisions.

You could also leave the user profile URLs like /user1, and add /business/macdonalds as a new scheme for business profiles.

Finally, it is not impossible to do what you like, but it is more difficult, because there are several constraints :

  1. You must make sure that a user name never is the same as a business name.
  2. You cannot redirect to either userprofile.php or businessprofile.php, but you have to redirect to a script (e.g. index.php) that does the routing.
  3. You have to develop a router, that will lookup the users and business tables to find out which type of profile has to be shown, and finally execute the correct .php file.
0
On

You could do something such as:

RewriteEngine On
RewriteRule ^page/([^/]*)$ /businessprofile.php?businessname=$1 [L]
RewriteRule ^user/([^/]*)$ /userprofile.php?username=$1 [L]

Which would redirect a user profile for example to basecentre.co.uk/user/... and a business profile to basecentre.co.uk/page/...