Broken mod_rewrite—is it possible?

Oh, the strange things mod_rewrite does!

Broken mod_rewrite—is it possible?

Postby artvolk » Sun Feb 11, 2007 12:33 am

Is it possible to mod_rewrite not to substitute back-references?

This code works

Code: Select all
RewriteEngine on
RewriteBase /
RewriteRule ^test/testing/?$ test-testing.html


When accessing http://example.com/test/testing I've got http://example.com/test-testing.html

But if I change simply to
Code: Select all
RewriteRule ^test/([a-zA-Z]+)/?$ test-$1.html

I've got url: test-.html (so the $1 is empty, but rewrite works!)

Code: Select all
RewriteRule ^test/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/?$ ($0)_($1)_($2)_($3)_($4)_($5).html


When accessing http://example.com/test/first/second/third/
I've got URL:
/()_(second/)_()_()_()_().html

The bolded seemed to me very strange...

I've Apache/1.3.33 (Unix) mod_perl/1.29 on this server. I've copy of httpd.conf of this server so I can look for some config settings...
All this rewrites works on test machine and two other servers...
Last edited by artvolk on Sun Feb 11, 2007 10:46 pm, edited 1 time in total.
artvolk
 
Posts: 3
Joined: Sun Feb 11, 2007 12:24 am

Postby richardk » Sun Feb 11, 2007 2:40 pm

Try [a-zA-Z]+ and adding the [L] flag to the end of each rule.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby artvolk » Sun Feb 11, 2007 10:41 pm

Sorry, it was my typing error here, I've checked again this code and the problem remains:

Code: Select all
RewriteEngine on
RewriteBase /
RewriteRule ^test/([a-zA-Z]+)/?$ test-$1.html [L]
RewriteRule ^test/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/?$ ($0)_($1)_($2)_($3)_($4)_($5).html [L]
artvolk
 
Posts: 3
Joined: Sun Feb 11, 2007 12:24 am

Postby richardk » Tue Feb 13, 2007 11:05 am

Try
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^test/([a-z]+)/?$                   /test-$1.html     [NC,L]
RewriteRule ^test/([a-z]+)/([a-z]+)/([a-z]+)/?$ /$0_$1_$2_$3.html [NC,L]


If that doesn't work i don't think you'll be able to fix it with configuration directives (I don't know of any that would do this). It might be a bad install of either Apache or the regex libraries, you could try reinstalling.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby artvolk » Tue Feb 13, 2007 11:42 am

Thank you for advice, but it didn't help...

I've got httpd.conf from this server—there is no LoadModule for mod_rewrite but 'httpd -l' shows that mod_rewrite is compiled into the apache

Can this be an issue?
artvolk
 
Posts: 3
Joined: Sun Feb 11, 2007 12:24 am

Postby richardk » Tue Feb 13, 2007 11:53 am

I don't think so. If it's compiled in it (probably) doesn't need a LoadModule line. You could try adding one.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 14 guests

cron