PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Dec 11, 2017 2:44 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Jun 18, 2013 5:57 pm 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
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:

Syntax: [ Download ] [ Hide ]
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.


Top
 Profile  
 
PostPosted: Tue Jun 18, 2013 6:10 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
Syntax: [ Download ] [ Hide ]
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.


Top
 Profile  
 
PostPosted: Wed Jun 19, 2013 9:50 am 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
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.


Top
 Profile  
 
PostPosted: Wed Jun 19, 2013 1:54 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
I sure hope it's not the leading slash thing...
1.
Code:
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:
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.


Top
 Profile  
 
PostPosted: Wed Jun 19, 2013 2:03 pm 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
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:
Syntax: [ Download ] [ Hide ]
applying pattern '^ical/(.*)/(.*)/' to uri 'ical.php/all/all/'


The URL I had actually requested was:
Syntax: [ Download ] [ Hide ]
  1. ical/all/all/ 


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.


Top
 Profile  
 
PostPosted: Wed Jun 19, 2013 3:26 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
That would be MultiViews at work. Add a
Code:
Option -MultiViews

But if /ical.php/all/all/ works then /ical/all/all/ should too...


Top
 Profile  
 
PostPosted: Wed Jun 19, 2013 3:39 pm 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group