Regexp does not match all cases

Discuss practical ways rearrange URLs using mod_rewrite.

Regexp does not match all cases

Postby fberbert » Fri Jul 25, 2008 1:24 pm

Hi,

I've created a regexp to redirect all pages that is not verArtigo.php, index.php, userview.php, ..., verSubCategoria.php to verArtigo.php. Follow:

RewriteRule /artigos/[^(verArtigo\.php|index\.php|userview\.php|contarVoto\.php|impressora\.php|navegacao\.php|votar\.php|verSubCategoria\.php)].*$ /artigos/verArtigo.php

So when I access:

http://localhost/artigos/30_motivos_para_usar_o_Linux/

It works... and works most of other samples. But in some cases it doesn't match pattern, for example:

http://localhost/artigos/Servidor_de_em ... a_e_MySQL/

I'm confused on regexp syntax. I'd like to do:

RewriteRule /path/(anything except file1.php, file2.php or file3.php) /path/newURL

This is my quest: (anything except file1.php, file2.php or file3.php)

How can I create this rule?

Thanks.
fberbert
 
Posts: 1
Joined: Fri Jul 25, 2008 1:06 pm

Postby richardk » Fri Jul 25, 2008 3:34 pm

As far as I know, you can't use (...|...) inside [^...].
The NC flag makes the regular expression case insensitive (but i don't think that's really the problem).

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/artigos/(verArtigo|index|userview|contarVoto|impressora|navegacao|votar|verSubCategoria)\.php$ [NC]
RewriteRule ^artigos(/.*)?$ /artigos/verArtigo.php [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron