You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Johan Svedberg <jo...@svedberg.pp.se> on 2004/05/26 13:46:36 UTC

[users@httpd] Help with mod_rewrite

Hi!

How would I get RewriteRule /weblog/archives/?([^0-9]+)/ to exclude the
match of /weblog/archives/index.php? A zero-width negative look-ahead
regexp seems to be the solution, but I can't seem to  get the syntax for
it right. Does mod_rewrite even support this?

-- 
Johan Svedberg, johan@svedberg.pp.se, http://johan.svedberg.pp.se/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Help with mod_rewrite

Posted by Eugene Lee <li...@fsck.net>.
On Wed, May 26, 2004 at 02:14:05PM +0200, Johan Svedberg wrote:
: * May 26 13:54 André Malo <nd...@perlig.de>:
: > * Johan Svedberg <jo...@svedberg.pp.se> wrote:
: >
: > > How would I get RewriteRule /weblog/archives/?([^0-9]+)/ to exclude
: > > the match of /weblog/archives/index.php? A zero-width negative
: > > look-ahead regexp seems to be the solution, but I can't seem to  get
: > > the syntax for it right. Does mod_rewrite even support this?
: >
: > It does in 2.x, since PCRE are used there. But the better (faster) way
: > is probably:
: >
: > RewriteEngine On RewriteRule ^/weblog/archives/index.php$ - [L]
: > RewriteRule ^/weblog/archives/?([^0-9]+)/ yourreplacement
: 
: That does indeed work. Everything works well now, except for one thing.
: When I try to access /weblog/archives/ the second rule kicks in.
: However, with the latest addition, accessing /weblog/archives/index.php
: now works in the desired way. How would I make /weblog/archives/ behave
: in the same way? I hope this made any sence. :-)

How about adding another rule to redirect '/' to '/index.php'?

	RewriteEngine On
	RewriteBase /
	RewriteRule ^weblog/archives/$ weblog/archives/index.php [R]
	RewriteRule ^weblog/archives/index\.php$ - [L]
	RewriteRule ^weblog/archives/?([^0-9]+)/ /index.php?category_name=$1 [QSA]


-- 
Eugene Lee

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Help with mod_rewrite

Posted by Robert Andersson <ro...@profundis.nu>.
Johan Svedberg wrote:
> > RewriteEngine On
> > RewriteRule ^/weblog/archives/index.php$ - [L]
> > RewriteRule ^/weblog/archives/?([^0-9]+)/ yourreplacement
> 
> That does indeed work. Everything works well now, except for one thing.
> When I try to access /weblog/archives/ the second rule kicks in.

You might want to try:
    RewriteRule ^/weblog/archives/(index.php)?$ - [L]

Regards,
Robert Andersson

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Help with mod_rewrite

Posted by Johan Svedberg <jo...@svedberg.pp.se>.
* May 26 13:54 André Malo <nd...@perlig.de>:
> * Johan Svedberg <jo...@svedberg.pp.se> wrote:
>
> > How would I get RewriteRule /weblog/archives/?([^0-9]+)/ to exclude
> > the match of /weblog/archives/index.php? A zero-width negative
> > look-ahead regexp seems to be the solution, but I can't seem to  get
> > the syntax for it right. Does mod_rewrite even support this?
>
> It does in 2.x, since PCRE are used there. But the better (faster) way
> is probably:
>
> RewriteEngine On RewriteRule ^/weblog/archives/index.php$ - [L]
> RewriteRule ^/weblog/archives/?([^0-9]+)/ yourreplacement

That does indeed work. Everything works well now, except for one thing.
When I try to access /weblog/archives/ the second rule kicks in.
However, with the latest addition, accessing /weblog/archives/index.php
now works in the desired way. How would I make /weblog/archives/ behave
in the same way? I hope this made any sence. :-)

Here is my current configuration:

RewriteEngine On
RewriteBase /
RewriteRule ^weblog/archives/index.php$ - [L]
RewriteRule ^weblog/archives/?([^0-9]+)/ /index.php?category_name=$1 [QSA]
RewriteRule ^weblog/archives/?([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([_0-9a-z-]+)?/?([0-9]+)?/?$/index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA]

Regards,

-- 
Johan Svedberg, johan@svedberg.pp.se, http://johan.svedberg.pp.se/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Help with mod_rewrite

Posted by André Malo <nd...@perlig.de>.
* Johan Svedberg <jo...@svedberg.pp.se> wrote:

> How would I get RewriteRule /weblog/archives/?([^0-9]+)/ to exclude the
> match of /weblog/archives/index.php? A zero-width negative look-ahead
> regexp seems to be the solution, but I can't seem to  get the syntax for
> it right. Does mod_rewrite even support this?

It does in 2.x, since PCRE are used there. But the better (faster) way is
probably:

RewriteEngine On
RewriteRule ^/weblog/archives/index.php$ - [L]
RewriteRule ^/weblog/archives/?([^0-9]+)/ yourreplacement

nd

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org