Click to See Complete Forum and Search --> : Rewrite Rule


lego11
03-12-2006, 05:50 PM
I need some help writing a rewriterule for my .htaccess, heres what it needs to do.

a url ie:
www.domain.com/firedude/ or www.domain.com/firedude
would get directed (without the user knowing) to
www.domain.com/team/file.php?url=firedude
and
www.domain.com/firedude/contactus.html
would get directed to
www.domain.com/team/file.php?url=firedude&pg=contactus
then say
www.domain.com/firedude/contactus.html?edit=true
gets directed to
www.domain.com/team/file.php?url=firedude&pg=contactus&edit=true
...all without the user's browser address changing, with the use of the [L] flag I suppose.

Problems i've run into basicaly deal with real files/folders i'll need to access such as
www.domain.com/images/file.gif etc..
or
www.domain.com/signup.php

One last but,
firedude is going to change - ie url's will be domain.com/firecat or domain.com/frenchfry/ etc. none of the sub directories actualy exist execpt for the /images/ directories.

I'll need to write a rule that somehow knows not to apply the above rule to anything in the images or test directories or to any files in the root directory.

Scleppel
03-13-2006, 11:17 AM
Try this:
RewriteEngine On

# if it's a real file
RewriteCond %{SCRIPT_FILENAME} -f [OR]
# or a real directory
RewriteCond %{SCRIPT_FILENAME} -d
# do nothing
RewriteRule .* - [L]
# mod_rewrite stops and the below rules are ignored


# /firedude/ or /firedude --> /team/file.php?url=firedude
RewriteRule ^([^\./]+)/?$ /team/file.php?url=$1 [L]

# /firedude/contactus.html ---> /team/file.php?url=firedude&pg=contactus
# /anything/richard.html ---> /team/file.php?url=anything&pg=richard
# [QSA] appends the query string from the fake address to the real address
RewriteRule ^([^\./]+)/(.+)\.html$ /team/file.php?url=$1&pg=$2 [QSA,L]

lego11
03-13-2006, 04:51 PM
This works perfectly, right on que with what I needed, thank you very much!
I have one further question and rather then start another topic i'll just ask it here.
I've applied the above rule, it is my .htaccess.
Now I need to pass form info between pages ie a link like this: /firedude/contactus.html?subject=heyo&body=moreinfohere
Unfortuantly it wont work, my guess why is that the underlaying address is still: /firedude/contactus.html. When I try to echo the information echo ("subject: $subject, body: $body"); nothing is expressed for $subject or body.

would it be along the lines of...
RewriteRule ^([^\./]+)/(.+)\.html(.+)$ /team/file.php?url=$1&pg=$2$3 [QSA,L]
?

Scleppel
03-13-2006, 05:09 PM
Are you sure it doesn't work. The [QSA] flag should append the query string on from the fake URL to the real URL.

You could try this:
RewriteRule ^([^\./]+)/(.+)\.html$ /team/file.php?url=$1&pg=$2&%{QUERY_STRING} [L]

RewriteRule ^([^\./]+)/(.+)\.html(.+)$ /team/file.php?url=$1&pg=$2$3 [QSA,L]
RewriteRules only matches the bit after the domain and before the ?, eg. domain.tld/this/part.html?anything=here. Query strings are in the %{QUERY_STRING} variable.

Also, shouldn't it be $_GET['subject'] and $_GET['body'] ?