Forum Moderators: phranque

Message Too Old, No Replies

can not rewrite url

         

adipkn

11:05 am on Dec 5, 2008 (gmt 0)

10+ Year Member



I have a strange problem,

i have the following lines in my htaccess

RewriteEngine on
Options +FollowSymLinks
RewriteRule ^kj/([a-zA-Z0-9]+)/$ /kj/demo.php [L]

It is supposed to rewrite a url like /kj/variable/ to /kj/demo.php

It is working when i put 'variable' to anything other than 'demo'. But it stops working when i put 'variable' to 'demo'.

i have searched the set and have not found any answer yet.

Any help will be greatly appreciated.

thanks in advance.

Samizdata

12:54 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



(Edited because previously suggested code didn't work)

Are you flushing your browser cache before testing?

This seems to work fine for me:

RewriteRule ^kj/(.*)/$ /kj/demo.php [L]

...

[edited by: Samizdata at 1:17 pm (utc) on Dec. 5, 2008]

jdMorgan

3:16 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that both versions of this rule drop the requested URL-path-part that follows "/kj/"

So it is possible that whatever mechanism you are using to "GET" that URL-path-part within your script is failing because it sees its own name as the GET value.

Typically, such rules are written to explicitly pass the requested path to the script. Example:


RewriteRule ^kj/([a-zA-Z0-9]+)/$ /kj/demo.php?mypath=$1 [L]

However, if you're on Apache 2.x, you may be using AcceptPathInfo to pass this information, in which case that function may be getting confused. The operation of AcceptPathInfo is confusing, and I won't even attempt to describe or explain it here -- See the Apache core documentation for more information.

You can verify this as the problem by using a rule similar to what I posted, disabling AcceptPathInfo, and modifying your script to take the path-info it needs from the GET parameter "mypath".

Regardless of server version, this problem might also be caused by having MultiViews enabled. If you don't use MultiViews, turn them off (Options +FollowSymLinks -MultiViews).

Jim