473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is is possible to do this in PHP (redirection) ?

Hi,

I would like to do the following.
If the user types this URL in the browser:

http://www.mysite.com/john

I want it to be redirected to http://www.mysite.com/showuser?user=john

The same if the user types a different name, for example:
http://www.mysite.com/michael
In this case, I want it to be redirected to
http://www.mysite.com/showuser?user=michael

The thing is I don't want to create a different folder for each user.

Thanks a lot!

Jul 17 '05 #1
8 1400
On 2 Mar 2005 09:45:56 -0800, Star wrote:
http://www.mysite.com/john
I want it to be redirected to http://www.mysite.com/showuser?user=john


http://httpd.apache.org/docs/misc/rewriteguide.html

--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #2
Ewoud Dronkert wrote:
On 2 Mar 2005 09:45:56 -0800, Star wrote:
http://www.mysite.com/john
I want it to be redirected to
http://www.mysite.com/showuser?user=john
http://httpd.apache.org/docs/misc/rewriteguide.html

--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/

Thanks for the information. The problem is I don't own that server, so
I cannot change its internal settings. I just can upload php pages.
Is there anything that I can do?

Thanks

Jul 17 '05 #3
"Star" <st*****@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
: > http://httpd.apache.org/docs/misc/rewriteguide.html
:
: Thanks for the information. The problem is I don't own that server, so
: I cannot change its internal settings. I just can upload php pages.
: Is there anything that I can do?

As long as rewrites are permitted on the server, you can do them using
..htaccess files. If they're not permitted, you'll get a 500 error page...

Some of the stuff on that page is for httpd.conf files, but what you're
asking about can be done through .htaccess

Matt
Jul 17 '05 #4
Thanks, Matt. I'll try that.

Could anybody give an code example of what I need? I checked the page
that Ewoud Dronkert gave me,
but I'm very novice with PHP pages, and in that page there are all kind
of rules and I cannot find the one that I need.

Thanks a lot.

Jul 17 '05 #5
Star wrote:
Thanks, Matt. I'll try that.

Could anybody give an code example of what I need? I checked the page
that Ewoud Dronkert gave me,
but I'm very novice with PHP pages, and in that page there are all kind of rules and I cannot find the one that I need.

Thanks a lot.


I'm a bit of a novice with RewriteRules myself, but I _THINK_ the
following will work. Your webhost will have to have mod_rewrite and
allow .htaccess files, but many hosts do. Just place it in a file
named .htaccess (note the leading dot), and see what happens. Make
sure you've created a showuser.php file also, of course. Note that
this does a transparent redirect, that is, the browser URL bar will not
update with /showuser.php. The redirection occurs silently
server-side.

RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z])$ /showuser.php?user=$1 [QSA]

Jul 17 '05 #6
Ramius, thanks for your answer.

Unfortunately, it doesn't work. I got an 404 error message that says:

Not Found

The requested URL /john was not found on this server.

Any hints?

Thanks

Jul 17 '05 #7
"Star" <st*****@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
: Ramius, thanks for your answer.
:
: The requested URL /john was not found on this server.
:
: Any hints?
:

Put a /showuser.php script on the server!

Matt
Jul 17 '05 #8
Matt, of course, I have that file on the server.

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: Hans Dembinski | last post by:
Hi there, I run in a problem with a script, that shall work similar like the c-program "most". It should be able to get some text on execution via a pipe but also is interactive by the user via...
52
by: Gerard M Foley | last post by:
Can one write a webpage which is not displayed but which simply redirects the user to another page without any action by the user? Sorry if this is simple, but I am sometimes simple myself. ...
8
by: Luciano A. Ferrer | last post by:
Hi! I was following the http://www.seomoz.org/articles/301-redirects.php article, trying to do that with one of my test sites I added this to the .htaccess file: RewriteEngine On RewriteCond...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
1
by: comp.lang.php | last post by:
require_once("/users/ppowell/web/php_global_vars.php"); if ($_GET) { // INITIALIZE VARS $fileID = @fopen("$userPath/xml/redirect.xml", 'r'); $stuff = @fread($fileID,...
3
by: postindex | last post by:
Can I get whole commandline not only argument list. 1. When I command like this $ a.py filename 2. sys.argv is returns only argument list Is there a way to find out 'redirection'...
13
by: Massimo Fabbri | last post by:
Maybe it's a little OT, but I'll give it try anyway.... I was asked to maintain and further develop an already existing small company's web site. I know the golden rule of "eternal" URIs, but...
7
by: Computer Guru | last post by:
Hello All, I'm at my wit's end on this one, and would appreciate any help or insight that could be given. Environment: Windows Vista x64 ONLY Code: //START BUG
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.