The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Mod Rewrites

Well its been about 3 years since I worked on apache rewrites, and it sure shows. My web host is horrible and I have jsut had enough, so I want to move everything to a new host. The problem is, the site doesnt work on the new host. I really dont know why, but it seems as though the variables are not carrying over in the mod rewrites. Im sure my code is atrociously riddled with error, but I dont know why it worked before and now it doesnt. Here is what I have narrowed it down to:

So that is the rewite that worrks on the old server, but not on the new. I have even tried such things as thus:

====
RewriteRule (.*)/([A-Za-z]*[u])/$ /details.php\?z\=pleaseReturnaVariable
===
And still it will not return $z. I have tried countless escape character variations as well. It does however send me to the correct page (details.php), but no variable is being sent over. I spent about 3 hours on this and still no luck. I really want to get out of this web host before they "transition" and break things again.

Second, ARGH! You need to learn regex 'cause the biggest problem with mod_rewrite seen in this forum is the inappropriate use of (.*). Please have a read of my signature's linked tutorial Article and see if that doesn't help. (Hint: You do NOT escape characters in a redirection.)

Thanks, Ill read it tonight. The escape characters look funny to me too, but it has been 3 years since I've looked at that code. I dont know why i used it, I assume it has something to do with php but who knows. I will say that it works on my old system but I guess that doesnt matter now. I will try to use something more up-to-date.

Yeah I think I DO want to catch everything before the slashes, so as far as I can tell the expression is viable (note that I did not say efficient or perfect.) The problem is that the variable is not being passed. I am trying to figure out why this is and I just have no clue. My guess is that these rewites require the use of globals and that maybe the new host has them off or something.

Is this how rewrites work? I mean, in essence I am just sending a variable via the address bar, correct? How then could one use rewrites without the use of global variables?

I really hope that made sense; I have a dated and thus dilapidated understanding of programming. My expertise is in writing, but certainly not in this form.

Again, thanks for the help. I would hate to call one of my programmer buddies over to share the headache. I'm glad I have someone to talk to that is an expert in this area.

RewriteEngine on
# good!
RewriteRule (.*)/([A-Za-z]*[u])/$ /details.php\?z\=$1\&w\=$2 [L]
# That says to CAPTURE everything before a /,
# then CAPTURE zero or more uppercase or lowercase letters
# followed by a u (the square brackets aren't needed)
# and a / to terminate the string - too weird for me!
# The redirection does not use the atom created
# by the regex and should NOT have the \'s
# The [L] was added to TERMINATE the block statement
# so it's not ANDed with the next block statement
RewriteRule (.*)/([A-Za-z]*[u])$ /details.php\?z\=$1\&w\=$2
RewriteRule page(.*)/cost(.*)-(.*)/(.*)$ index\.php\?curpage\=$1\&p\=$2\&costy\=$3\&t\=$4
# ARGH! The same thing as above but then ANDed with
# another RewriteRule which must match page, ANYTHING/NOTHING,
# a /cost, another ANYTHING/NOTHING, a dash, a third
# ANYTHING/NOTHING, another / then ANYTHING/NOTHING and
# redirect to ... it doesn't matter 'cause it'll NEVER match after
# the prior redirection.
RewriteRule (.*)/([A-Za-z]*[u])/$ /details.php\?z\=pleaseReturnaVariable
# Ditto the first explanation including the \'s in the redirection
# and the lack of definition of pleaseReturnaVariable

I suspect that your understanding of regex is what's at fault (the reliance on (.*) gives that away!) but, the [u] makes me think that you want to have '[u]' IN your URL - it won't happen! Have a look at http://www.ietf.org/rfc/rfc2396.txt which will show you which characters are allowed in a URL and under what conditions.