Jump to content

mod_rewrite woes


Crusader

Recommended Posts

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 :)

Link to comment
Share on other sites

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 ON

RewriteCond  /your/docroot/%{REQUEST_FILENAME} !-f

RewriteCond  /your/docroot/%{REQUEST_FILENAME} !-d

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

 

This is what can forward /~user


RewriteEngine ON                                                                                                    

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

 

Hope this helped!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

hmmm its not working for me...

 

Options +FollowSymlinks

RewriteEngine 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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.