Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite syntax error?

         

lorax

8:34 pm on Dec 13, 2003 (gmt 0)

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



A simple rule

RewriteRule ^fake-dir-name/(.*)\.html$ fake-dir-name.php?x=$1 [T=application/x-httpd-php]

The link is in the form of h**p://www.domain.com/dir/fake-dir-name/var.html

The file fake-dir-name.php is under the directory /dir/ as the URL indicates.

I've been banging my head against the wall for the past hour and can't see the error. If I manually pass the var on the URL it works great. A test for 'x' shows it isn't being set.

I've used this exact code only without trying to include a fake sub directory and it works great. What did I miss/mess up?

jdMorgan

10:16 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lorax,

This is just a regular-expressions issue. Take the start anchor (^) off the pattern in your RewriteRule. Or alternatively, specify the full path to the resource in the pattern and use the start anchor (this will restrict the rule to operating only for that specific directory/subdirectory path, though).

So, either


RewriteRule [b]f[/b]ake-dir-name/(.*)\.html$ fake-dir-name.php?x=$1 [T=application/x-httpd-php]
- or -

RewriteRule [b]^dir/f[/b]ake-dir-name/(.*)\.html$ fake-dir-name.php?x=$1 [T=application/x-httpd-php]

should work.

Jim

lorax

2:10 am on Dec 14, 2003 (gmt 0)

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



Thanks jdMorgan,
I tried both ways and it still doesn't work.

Well I got it to work but the URL was horrible. All of the files for this scheme are in /dir/. SO in order to get it to work I had to use the relative path /dir/fake-dir-name/var.html.

The regex for the rewrite rule was dir/fake-dir-name/(.*)\.html$ The URL comes out as h**p://www.domain.com/dir/dir/fake-dir-name/var.html

So I figured all I needed to do was to drop the /dir/ from the link and the regex. Nada

I know I'm close.

lorax

2:52 am on Dec 14, 2003 (gmt 0)

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



Ah... got it.

/(.*)\.html$ fake-dir-name.php?x=$1

Now I realize that the fake-dir-name needs to be a variable too. Here we go again. ;)

<added>
Twasn't that bad. Finally got it sorted out. Thanks for the help. The answer is

(.*)/(.*)\.html$ $1?x=$2

How much simpler could it be?

jdMorgan

4:05 am on Dec 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah yes... Simple, quite so. ;)

Glad you got it working!

Jim