Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite troubles

?

         

l008comm

9:32 pm on Nov 22, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm having a hell of a time writing what seems to be a pretty simple rewrite rule. The desired effect is to turn:
www.site.com/information/[townname]
into
www.site.com/information/index.php?town=[townname]
while leaving
www.site.com/information
as is. I'm trying to do this in .htaccess files because I'm on a paid host and have no access to .conf files. If anyone knows what they are doing and wants to help, I thank you.

jdMorgan

9:45 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



l008comm,

Welcome to WebmasterWorld!

Post your code, and we'll have a look. Also, see our charter [webmasterworld.com] for some helpful links.

Jim

l008comm

10:02 pm on Nov 22, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



RewriteRule ^information/([a-zA-Z]+) information/index.php?town=$1 [L,PT]

I have that and it seems to be passing /information/index.php?town=index

I have no clue why. I tried turning on logging of modrewrite but it kept shutting down my whole site with 505 errors. Very frustrating.

Also, the site woudln't let me register my normal user name l008com, because it ends with 'com'? Is it possible for you guys to manually change my name from l008comm to l008com?

Thanks

jdMorgan

12:31 am on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> it seems to be passing /information/index.php?town=index

> it kept shutting down my whole site with 505 errors.

Probably related problems, and most likely due to recursion; Once mod_rewrite does a rewrite in .htaccess, then the whole URL-processing phase starts over. So, if your rule's pattern matches the new local URL-path, it'll be rewritten again, ad infinitum, or actually until the server's rewrite limit is reached. So, the second time through, "index" is what will be found in the position you are back-referencing.

After your first post, here's what I came up with:


RewriteCond %{REQUEST_URI} !^/information/index\.php$
RewriteRule ^information/(.+)/?$ /information/index.php?town=$1 [L]

The first line keeps the rule from being applied if the local URL-path is already "/information/index.php", and so prevents recursion.

I didn't include the [PT] flag. It shouldn't be needed. But if this doesn't work, put it back in and see if that helps. [PT] allows passing the URL output of mod_rewrite through to mod_alias, mod_access, etc. for further processing. With a simple rewrite like this, it shouldn't be necessary.

Jim