Jump to content


Photo

mod_rewrite woes


  • Please log in to reply
10 replies to this topic

#1 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 17 July 2003 - 03:49 AM

gah....

how can i do this?

I have a php page which calls on a specific variable
(http://boo.com/bah.php?user=username)
i want it to look like this though, http://boo.com/username

how would i do this?

i tried doing this:

RewriteEngine On  
RewriteRule ^/(.*)  /view.php?user=$1


but i had no success...
thanks for reading and or trying to help :)

#2 MAPA3M

MAPA3M
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationNew York

Posted 17 July 2003 - 06:59 AM

RewriteEngine OnRewriteCond ! http://boo.com/%{REQUEST_URI} -URewriteRule http://boo.com/(.*) http://boo.com/view.php?user=$1

Just a wild guess, but it might work
# cd /pub [br]# more beer

#3 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 17 July 2003 - 08:41 AM

err it gave me an internal server error :) thanks for trying though

#4 MAPA3M

MAPA3M
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationNew York

Posted 17 July 2003 - 09:03 AM

This is an interesting problem... let me get off work and get to an Apache server I\'m not afraid to break :-) I\'ll work on it then
# cd /pub [br]# more beer

#5 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 18 July 2003 - 04:50 AM

ty :)

#6 MAPA3M

MAPA3M
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationNew York

Posted 18 July 2003 - 08:19 AM

This is a tricky one... how do you tell if the request is invalid or is for a user or is for a regular file?

for example... you have a user \"john\".... this would make the request

http://www.blah.com/john

valid from the logical point of view... however, to Apache that request and

http://www.blah.com/no-such-user
and
http://www.blah.com/index.html

will look exactly the same... so while I did set up a mod_rewrite that\'ll do what you want, it doesn\'t seem very useful because apache will rewrite EVERY REQUEST that\'s 404 to view.php?user

Best that you can do is something like

http://www.blah.com/~validuser

That way you can either use apache\'s mod_userdir or set up a simple mod_rewrite rule to forward those users

Now, for reference....
This is the answer to your original question...maybe you can improve on it
RewriteEngine ONRewriteCond  /your/docroot/%{REQUEST_FILENAME} !-fRewriteCond  /your/docroot/%{REQUEST_FILENAME} !-dRewriteRule ^/(.*) /view.php?user=$1

This is what can forward /~user
RewriteEngine ON                                                                                                    RewriteRule ^/~(.*) /view.php?user=$1

Hope this helped!
# cd /pub [br]# more beer

#7 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 18 July 2003 - 09:12 AM

thanks MAPA3M!

to solve this i was thinking of adding a query to the view page. im probably going to make it an else, so if it doesn\'t detect a user it will instead do a query through a list of files listed in the db, eg. if someone looked for forums it would fail the user query and else to find that there is a forum entry in the site table. if both queries failed it would then bring them to some other page. or so i hope lol. i\'ll post on how i(f) solve this.

thanks.

#8 MAPA3M

MAPA3M
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationNew York

Posted 18 July 2003 - 09:14 AM

That seems very insecure and error-prone.... why not just go with the /~username setup? Worked for everyone for years and is close to being foolproof
# cd /pub [br]# more beer

#9 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 18 July 2003 - 10:09 AM

yea i think ill need to use that heh. any idea how xanga.com does it? check out http://xanga.com they\'re running on asp but i dont get how that would make much of a difference.

aghh.. finding the root to the subdomain is annoying... it does not want to cooperate with the sub lol

#10 MAPA3M

MAPA3M
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationNew York

Posted 18 July 2003 - 09:37 PM

Xanga seems to be doing it the way that I wrote... if the file or directory doesn\'t exist, rewrite it to home.asp?user=blah
# cd /pub [br]# more beer

#11 Crusader

Crusader
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationCanada

Posted 19 July 2003 - 07:30 AM

hmmm its not working for me...

Options +FollowSymlinksRewriteEngine ON RewriteCond  /home/virtual/site34/fst/var/subdomain/gc/html/%{REQUEST_FILENAME} !-f RewriteCond  /home/virtual/site34/fst/var/subdomain/gc/html/%{REQUEST_FILENAME} !-d RewriteRule ^/~(.*) /view.php?user=$1

im pretty sure i have the right root. could it not working have to do with it running on one of my subdomains?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users