Welcome to WebmasterWorld Guest from 3.80.6.254

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

mod_rewrite syntax error?

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

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


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?

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

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

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


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.

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

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


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?

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

Glad you got it working!

Jim