FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Redirection Varible Folders (That dont exsist)





moejoe
Hi!

Most of us have tried MySpace.com - They have a system where you can choose a 'nickname' and that nick name turns into
www.myrepospace.com/nickname

I'm trying to, with the help of PHP, have something similar to my users where:
example.com/username Redirects to:
example.com/user.php?id=username

I have a little knowledge of .htaccess so use as much noob talk with me as possible.

Thanks in Advance.
moejoe
Hi,

Well i found some more information on the subject:

This worked for me:

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ gotopage.php?varible=$1 [R]


Unfortunately, Now Frontpage does not work due to some issues when you turn on RewriteEngine.

Anyone have a fix for this?
Fire Boar
You could always do...

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/(.*)$ gotopage.php?varible=$1 [R]


Then have a <base href="http://www.yoursite.com/" /> in your <head> tag for the user's pages. That will only redirect things that appear to be in the users/ folder. Or you could add in another RewriteCond to ignore the front page only.
richard270384
I learnt URL rewriting a while back.

Here are a few links that I bookmarked at the time:

http://corz.org/serv/tricks/htaccess2.php
http://www.tutorio.com/tutorial/enable-mod-rewrite-on-apache
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

It's very easy. If it helps you learn any, here is what my .htaccess looks like for one of my sites (so I know this code works):

Code:
Options +FollowSymlinks

RewriteEngine on

RewriteRule ^articles/([^/.]+)/([^/]+)/?$ /index.php?a=content&id=$1
RewriteRule ^articles/([^/.]+)/comments/add/?$ /index.php?a=comment_add&id=$1
RewriteRule ^articles/([^/.]+)/comments/save/?$ /index.php?a=comment_save&id=$1

RewriteRule ^tags/([^/.]+)/?$ /index.php?a=tag_show&t=$1

RewriteRule ^users/([^/.]+)/?$ /index.php?a=user_show&u=$1

RewriteRule ^users/([^/.]+)/recent-activity/?$ /index.php?a=user_show&u=$1&s=recent_activity
RewriteRule ^users/([^/.]+)/submitted-articles/?$ /index.php?a=user_show&u=$1&s=submitted_articles
RewriteRule ^users/([^/.]+)/favourite-articles/?$ /index.php?a=user_show&u=$1&s=favourite_articles
RewriteRule ^users/([^/.]+)/liked-articles/?$ /index.php?a=user_show&u=$1&s=liked_articles
RewriteRule ^users/([^/.]+)/favourite-writers/?$ /index.php?a=user_show&u=$1&s=favourite_writers
Related topics
Help Needed Regarding CGI And Php
WTF IS GOING ON
HI, Any one know this program??
My web site !
Server time
HTML + PHP problem
tweaking wordpress
Disabling "This is a string with a $var"?
Email Question
PHP Comprehensive Tutorials
i cant load my index.php
Please help my crappy php skills need help
where to start in php
Protect Your PHP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.