Forum Moderators: phranque

Message Too Old, No Replies

.htaccess broken?

I can't make it work!

         

stormshield

6:07 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



I've been struggling with this problem for quite a long time with no positive result. What I want to do is translate [zxc.com...] into
[zxc.com...] I tried this code:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)/?$ $1.php?id=$2&id2=$3

but it doesn't work. It's particularly weird because when I repalce "/" with "_", it works fine, which makes me think something is broken.

Anyone?
Storm

smatts9

9:40 pm on Aug 17, 2006 (gmt 0)

10+ Year Member




<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /$1.php?id=$2&id2=$3 [L]
</IfModule>

Try this it should work.

stormshield

10:28 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



Nope :( Doesn't work. The page stored in $1 appears but it doesn't seem to see $2 and $3.

smatts9

10:54 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



I tested it on my own site, and it worked. When I typed into my browser:

site.com/display/2/3/

It came up with what I had for:

site.com/display.php?id=2&id2=3

I put some echo's in my display.php to display what the ID's were equal to and it worked?...

In your orignial post you put:


[zxc.com...]

Did you mean display? or display.php?

stormshield

11:25 am on Aug 18, 2006 (gmt 0)

10+ Year Member




<I put some echo's in my display.php to display what the ID's were <equal to and it worked?...

Yes, that's exactly what I'm trying to achieve.

In your orignial post you put:

[zxc.com...]

<Did you mean display? or display.php?

I meant display.php

After this post and hundreds of acticles I have seen, I'm almost sure that mod rewrite with slash is just turned off in my case (if it's possible - I don't know Apache servers at all)... it is probable because it's my father's server, maintained by a hired worker. I already sent him an email but it turned out that he had gone on his vacation. Is there some way to get a report on mod rewrite, all configuration and etc? Perhaps, then I could find the source of this problem.

Thanks

jdMorgan

1:29 pm on Aug 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no option to 'turn off slashes' or anything that specific. mod_rewrie is a small module in a very simple server program (as compared to something huge like windows), and most implementation problems are caused by over-estimating how smart it is, rather than by underestimating how simple it is. Its simplicity and small size are demonstrated by the fact that an excellent use for an old i386 PC is to put Apache on it, and turn it into a server capable of quickly handling any reasonably-sized Web site (As long as you don't try to put a huge site like Amazon.com on it, that is)... Anyway, Apache is small, simple, fast... You know... Not like an MS product. :)

I don't want my point to get lost there in my dig at Gates & Co., but what I mean is that Apache is simple, and it's bugs tend to be simple... As long as the load is good.

Your code looks fine, even though smatts' tweaks should make it faster. In addition, since he was kind enough to test it for you on his server and it worked, this is obviously a problem specific to your server.

This sounds like a bad or corrupted copy of either mod_rewrite or the regular-expressions library in the OS (which is used by mod_rewrite). You'll need to wait for your admin, or hire someone else locally to look into reinstalling those components.

It's also possible you've got a very old or 'strange' regular-expressions library in the OS. I suppose you could try escaping the slashes in the patterns, but this should absolutely not be necessary on any modern Apache load with a modern regex library -- e.g. ^quux\/foo\/bar\.php$

Jim

stormshield

10:57 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



Hi Jim, thanks for your exhausing reply. As for the problem, I now have 2 ways: to wait for the administator to come back or try to fix it by myself. I guess I'll choose the former - I don't feel like wasting many hours on something that doesn't guarantee success. Anyways, thanks again for your input (Smatt's too).

Storm