Web Hosting Talk







View Full Version : mod_rewrite 'tricking' of browsers


skoop
11-23-2002, 11:14 AM
hey all,

Ive had a look around but couldn't really find anything for this situation yet (or else missed it, in which case you can call me stupid ;) )

anyway, the situation is this: for a new site I'm working on I want www.domainname.com/username to be 'the same' as www.domainname.com/content.php?username

now i know this should be possible with mod_rewrite. after a few tutorials on the web I thought the following line should work:

RewriteRule ^(/.*)$ /main.php?$1

this doesn't work, it simply gives an error 404 when requesting www.domainname.com/skoop ...

I've also tried a few variations, but this didn't really result in anything worthy either, cause that gave errors 404, 500 or even no traffic back to me after requesting it ...

can anyone tell me how to do this?

stefan

beowulfdk
11-23-2002, 02:13 PM
Remembered:
RewriteEngine on

? Except for that I cant really tell you what is wrong, since my mod_rewrite skills are == ZERO

Also there is another way to do it I guess. Like most of these url forwarding services work; in htaccess set errordocument to a php file, ie:
ErrorDocument 404 /contents.php
ErrorDocument 401 /contents.php

In contents.php you can then parse the requested url to figure out which file to display and then just "include();" it :-) One advantage of this approach is that you can check whether the user exists, coutn visitors etc. - if your users are in a database.

skoop
11-24-2002, 06:06 AM
yeah, I turned the rewrite engine on... I didn't post it caused it seemed so logical :D

that errordocument trick is nice as well ... must remember that :)

bear
11-24-2002, 08:40 AM
Originally posted by skoop
anyway, the situation is this: for a new site I'm working on I want www.domainname.com/username to be 'the same' as www.domainname.com/content.php?username

now i know this should be possible with mod_rewrite. after a few tutorials on the web I thought the following line should work:

RewriteRule ^(/.*)$ /main.php?$1

this doesn't work, it simply gives an error 404 when requesting www.domainname.com/skoop ...You want to redirect to 'content.php', but your ReWrite code shows 'main.php'?

skoop
11-24-2002, 02:29 PM
oh right... I've done a bit of trying with different filenames. :D

my bad. but it doesn't work with content.php and with main.php :D

skoop
11-27-2002, 03:56 AM
ok. the following seems to work for me:


Options ExecCGI FollowSymLinks Includes MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^([^.]+)$ /main.php?url=$1


for future reference by others that need this ;)