Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Tue Jun 18, 2013 5:57 pm
I've just build a Debian box and migrated an app from an older SuSe box. This app has a large-ish .htaccess file with a bunch of mod_rewrite rules. All of these rules work perfectly fine on SuSe, but some of them don't on Debian. The file looks like this:
Code: Select all
RewriteEngine on
# These three rules work
RewriteRule ^month/([0-9]*)/([0-9]*)/(.*)/(.*)/ schedule.month.php?month=$1&year=$2&category=$3&location=$4 [L]
RewriteRule ^week/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)/(.*)/$ schedule.week.php?year=$1&month=$2&day=$3&category=$4&location=$5 [L]
RewriteRule ^day/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)/(.*)/$ schedule.day.php?year=$1&month=$2&day=$3&category=$4&location=$5 [L]
# The rest don't
RewriteRule ^ical/(.*)/(.*)/ ical.php?category=$1&location=$2 [L]
RewriteRule ^mine$ /eventus/mine/event/asc/ [R] # requested: /eventus/mine
RewriteRule ^mine/$ /eventus/mine/event/asc/ [R] # requested: /eventus/mine/
RewriteRule ^mine/([^/]*)$ /eventus/mine/$1/asc/ [R] # requested: /eventus/mine/blah
RewriteRule ^mine/([^/]*)/$ /eventus/mine/$1/asc/ [R] # requested: /eventus/mine/blah/
RewriteRule ^mine/([^/]*)/([^/]*)$ /eventus/mine/$1/$2/ [R] # requested: /eventus/mine/blah/blah
RewriteRule ^mine/(.*)/(.*)/$ mine.php?sort=$1&direction=$2
RewriteRule ^new/$ new.php [L]
RewriteRule ^edit/([^/]*)/$ edit.php?id=$1 [L]
RewriteRule ^approve/(.+)$ approve.php?code=$1 [L]
RewriteRule ^approve/$ approve.php [L]
RewriteRule ^todo/ todo.php [L]
RewriteRule ^import/$ import.php
I've moved some of the no-longer-working rules to the top, above the rules that do work, with no change - so it doesn't appear the working rules are breaking the rest.
Any ideas?
Edit Strange - some .htaccess files are working, others are not. As far as I can tell they're pretty much exactly the same.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Jun 18, 2013 6:10 pm
Code: Select all
RewriteRule ^mine$ /eventus/mine/event/asc/ [R] # requested: /eventus/mine
RewriteRule ^mine/$ /eventus/mine/event/asc/ [R] # requested: /eventus/mine/
RewriteRule ^mine/([^/]*)$ /eventus/mine/$1/asc/ [R] # requested: /eventus/mine/blah
RewriteRule ^mine/([^/]*)/$ /eventus/mine/$1/asc/ [R] # requested: /eventus/mine/blah/
RewriteRule ^mine/([^/]*)/([^/]*)$ /eventus/mine/$1/$2/ [R] # requested: /eventus/mine/blah/blah
Since when did end-of-line comments work? Isn't the entire line or nothing? But that doesn't explain the other rules not working.
Can you confirm the rules aren't matching at all? Throwing in [R,L]s doesn't redirect? IIRC you do need the [L] even for redirects.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jun 19, 2013 9:50 am
Nope, putting [R,L] at the end of the rules doesn't do anything.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Jun 19, 2013 1:54 pm
I sure hope it's not the leading slash thing...
1.
Code: Select all
RewriteRule ^/?ical/(.*)/(.*)/ ical.php?category=$1&location=$2 [L]
RewriteRule ^/?mine$ /eventus/mine/event/asc/ [R] # requested: /eventus/mine
RewriteRule ^/?mine/$ /eventus/mine/event/asc/ [R] # requested: /eventus/mine/
...
(throwing in a /? at the beginning)
2. Stick a
Code: Select all
RewriteRule .* /somewhere/safe/?url=$0 [L,R,QSA]
at the start of the broken Rules and check the ?url value to see what mod_rewrite is trying to match against.
3. There's a URL rewriting log you can enable but I don't know what it includes.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jun 19, 2013 2:03 pm
1) Didn't do anything
2) Had no change. Which is really odd because it's hard to screw up a rule that simple. I'm beginning to wonder if it's a misconfiguration of some sort.
3) I'll look into that.
Thanks for your input
Update: After enabling the rewrite log and testing, one line popped out to me:
Code: Select all
applying pattern '^ical/(.*)/(.*)/' to uri 'ical.php/all/all/'
The URL I had actually requested was:
[syntax]ical/all/all/[/syntax]
But for some reason ".php" was appended. If I actually request "ical.php/all/all", the request works.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Jun 19, 2013 3:26 pm
That would be MultiViews at work. Add a
But if /ical.php/all/all/ works then /ical/all/all/ should too...
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jun 19, 2013 3:39 pm
Yep, MultiViews was the problem. I actually discovered that about 45 minutes ago but hadn't got around to updating this thread. Full points for the solution though.
Thanks again.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.