httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hicks <>
Subject Re: [users@httpd] modRewrite looks in the wrong subfolder: http://localhost/module/News/article/56.html => http://localhost/index.php?module=News&article=56
Date Thu, 20 Apr 2006 02:38:46 GMT
Bernd Muent wrote:
> Hi together,
> I'd like the following for a CMS:
> URL http://localhost/module/News/article/56/show/1.html
> will be rewrited to
> http://localhost/index.php?module=News&article=56&show=1
>  From the PHP site, it's easy to explode the querystring and prepare the 
> right link.
> When I click the first time on:
> http://localhost/module/News/article/56/show/1.html
> everything is ok, but then the link becomes the following:
> http://localohost/module/News/article/56/show/1/module/News/article/56/show/1.html 
> So Apache thinks that "module/News/article/56/show/" is the current 
> folder and he is looking in this subfolder.
> After that I get either a 404 or embedded pictures are not found.
> My rewrite rules are the following:
> RewriteRule ^(.*)/(.*)(\.html?)$ /index.php?$1=$2 [L]
> RewriteRule ^(.*)/(.*)/(.*)(\.html?)$ /index.php?$1=$2&$3 [L]
> RewriteRule ^(.*)/(.*)/(.*)/(.*)(\.html?)$ /index.php?$1=$2&$3=$4 [L]
> RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)(\.html?)$ 
> /index.php?$1=$2&$3=$4&$5 [L]
> etc.

I think the problem is not with your modRewriting but simply the way 
you're building your links. If you make sure they begin with a "/", they 
will be appended to the root of the domain. Without the "/" the link 
will be appended to the directory for the current page. (The user's 
browser does this, not Apache.)

e.g. Your link should be:
<a href='/module/News/article/56/show/1.html' >

and not:
<a href='module/News/article/56/show/1.html' >

It sure looks like that is your problem.

Now, as an aside:

A regular expression tends to be "greedy," i.e. to gobble or consume as 
much of the string as it can when it can.

So generally something like:
should be:

so that the parenthesized expression doesn't consume more than one 
directory at a time.

But I don't think that's what's causing this problem. It's your html 
links themselves.

Hope that helps,


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message