How can I use more than ONE vanity URL? - php

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!

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 :
You must make sure that a user name never is the same as a business name.
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.
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.

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/...

Related

Correct redirect (header redirect) and change the language on the site

I have some issues while developing my site. I want to realize multilanguage web site, but i don't know how to make correct redirecting for visitors.
For example, the user has come to my web site http://web-site.com/ua/ he sees the default language, and when he walk around through the site he needed to change to english language http://web-site.com/en/.
And now is the problem, how should i realize the next, when he is on product page or other, for example now is:
http://web-site.com/ua/automotive/wheels/product_url
and he is changing language, so now url would be look like this:
http://web-site.com/en/automotive/wheels/product_url
But i don't know how to make the redirect for the same url but with /en/ instead of /ua/. Can some one help me? Or what solutions would be better.
My .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !^favicon\.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
Or maybe it would be better make some redirects in .htaccess from http://web-site.com/ to http://web-site.com/en/. But this is another question.
I did my own router, not like the usual MVC routers, but very similar. If necessary, i will add it below at this question.

Redirecting traffic from a certain URL to a certain page

Happy Friday!
I'm trying to create a redirect via .htaccess, basically when a user visits our old support system, it will send them to the IP of the new support system... Via HTACCESS I created the following:
RewriteCond %{HTTP_REFERER} oldsystem.domain.com [NC]
RewriteRule .* http://newsystem.domain.com/pages/wiki-has-moved/ [R,L]
However, this fails to point the user from the homepage of the new system.... Please could someone help me achieve this redirect?
Note - I followed this question, but the results aren't working with the redirect from .htaccess:
Allow access to a certain page on a site, only if they come from a link on another certain page
Note 2 -
The systems are on two separate servers, both with different IP's. However, they DO use the same domain oldsystem1.domain.com & newsystem1.domain.com.
Note 3-
We still want users to be able to access the old content (staff members) but non staff members will be redirected to the new system. This is why we have had to point the redirect to an IP.
This is how I managed to overcome the issue:
RewriteCond %{HTTP_HOST} ^wiki.volocommerce.com$
RewriteRule ^(.*)$ http://hub.volocommerce.com/pages/wiki-has-moved/ [R=301,L]
RewriteCond %{HTTP_HOST} ^wiki.esellerpro.com$
RewriteRule ^(.*)$ http://hub.volocommerce.com/pages/wiki-has-moved/ [R=301,L]
Hope this helps anyone else :)
Have you activated the rewrite engine? Your htaccess should look like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.2.3.4 . // replace with allowed ip address
RewriteRule .* http://newsystem.domain.com/pages/wiki-has-moved/ [R,L]
If it should be a permanent redirect add this [L,R=301] instead of [R,L], so the browser will keep the redirect in cache and directly switch to the new site without getting redirected again.
If you want to allow multiple ip addresses you can add multiple conditions like:
RewriteCond %{REMOTE_HOST} !^1.2.3.4 [OR]
RewriteCond %{REMOTE_HOST} !^5.6.7.8

ReWrite Rule for Dbname as common subfolder

Could someone please help me with the following re-writes for Apache
I want the results to be:
domain.com/ (Landing search page for which DB username belongs to)
domain.com/db1/ (For index login page to db1 where db1 can be any other db name)
domain.com/db1/accounts/ (Once logged in)
domain.com/db1/admin/ (Another page once logged in)
Please help me with a url re-write if it is possible to do this...
I have something like this but it's not working:
`Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*)/$ /index.php?dbname=$1
RewriteRule /(.*)/account/$ /account.php?dbname=$1
`
Thank you
Regards
Johan
Avoid rewriting calls to /
Just present the login form in index or in whatever other page you want.
Then
This block tells the server to allow rewriting, to stick with existing files and directories and only rewrite what does not "exist", and that you will be rewriting from /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
then your rules
RewriteRule ^db([0-9]+)$ index.php?dbname=$1&%{QUERY_STRING} [L]
RewriteRule ^db([0-9]+)/account$ index.php?admin=$1&%{QUERY_STRING} [L]
RewriteRule ^db([0-9]+)/admin$ index.php?admin=$1&%{QUERY_STRING} [L]
This is assuming that after login you will be sending him to
https://www.yoursite.com/db1
https://www.yoursite.com/db1/account
https://www.yoursite.com/db1/admin
for instance

RewriteRule different pages per user

I am deciding to create separate profile links for each user who registers on the website. I am using the .htaccess file RewriteRule to achieve this. The url I want to achieve should look something like www.domain.com/username. (I don't want www.domain.com/users/username)
Now the problem is, if I add a rule like RewriteRule ^(.*)$ /users.php?username=$1
it will matchup all URL addresses for www.domain.com, which may direct to any path. Even if I would like to visit www.domain.com/about page, it will be redirected to
www.domain.com/users.php?username=about, which I don't want. (Even if the requests was www.domain.com/products/abc)
I could apply filters in my users.php to filter such usernames, or if a username is not found in database, redirect to the page, but this means I have to change filters every time I decide to add a new page in my directory (in this case, any). Also, all traffic will be directed through 1 page, which may cause a performance problem.
Please suggest a way to achieve this, as There are websites that work like this. A possible RewriteRule or PHP code to achieve this.
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)/?$ /users.php?username=$1 [L,QSA]
I always use just simple rewrite as below:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)(.*)/?$ index.php
All traffic is redirected to index.php and using php I can run specific controllers depending on url. You should also think about. Almost all frameworks use such rule.
Then in your PHP file you should examine
$_SERVER['REQUEST_URI']
variable to route request to specific controllers

Mod rewrite user URL

I'm lost here. I'm using this script to give users the opportunity to enter their username lijke this:domain/username
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ userpage.php?user=$1 [NC,L]
</IfModule>
This works fine. However, every user has pages I must link to: Video, Music, Images etc...
So I need something like:
domain/username/video
In php code it must be something like:
user.php?user=test&page=video
And one other question: What is the preferable way to link in this situation?
userpage.php?user=test&page=video
or
/test/video
And finally: Is it possible to deny the possibility to enter the url:
domain/userpage.php?user=test&page=video? Instead just always show: domain/test/video
Thanks in advance
I'm not 100% sure what you're asking? Do you need to change the rewrite rule to match the URL site.com/moonwalker/videos? You could try this:
RewriteRule ^([^/]+)/(images|videos|music)/?$ userpage.php?user=$1&page=$2 [NC,L]
Update
Just a quick note on the domain/member/videos URL structure. That could end up causing you problems in the future. For instance what if you decide to have a single page that shows all member videos? You'd probably want to URL to look something like site.com/members/videos. That's a problem, because the rewrite rule will also match that, but "members" isn't a member username.
I would probably structure my member page URLs like site.com/user/moonwalker/videos so it doesn't clash with future rewrite rules. You would change the above rewrite rule to this:
RewriteRule ^user/([^/]+)/(images|videos|music)/?$ userpage.php?user=$1&page=$2 [NC,L]
Then later on you can add a rewrite rule like:
RewriteRule ^members/(images|videos|music)/?$ allusers.php?page=$1 [NC,L]
To show all member videos.
Yes, it is possible by looking at the request line:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /userpage\.php[?\ ]
RewriteRule ^userpage\.php$ - [F]
This is necessary as the URL path could already be rewritten by another rule and thus using just RewriteRule would match those already rewritten requests too.

Categories