LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 12-30-2009, 01:08 PM   #1
deesto
Member
 
Registered: May 2002
Location: NY, USA
Distribution: FreeBSD, Fedora, RHEL, Ubuntu; OS X, Win; have used Slackware, Mandrake, SuSE, Xandros
Posts: 448

Rep: Reputation: 31
Question Apache rewrites screwing up images


I have an Apache proxy config with a ton of rewrites to other servers, so in order to handle the "trailing slash problem" in one place, I had added this to the beginning of a virtual host file:
Code:
Options +FollowSymlinks
RewriteEngine on
RewriteLogLevel 0
# any URL request missing a trailing slash gets one:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(/)$
RewriteRule (.*)$ $1/ [R,NC]
This works great, with the exception of one rewrite (that I know of so far), which is still adding the trailing slash to the end of every URL referred to by a page, including images (e.g., 'image.jpg' is being turned into 'image.jpg/', which doesn't exist). The rule for that one is currently:
Code:
RewriteRule ^/somesite/(.*)$ http://some.server.com/somesite/somelongpath/$1 [R=301,NC,L]
The thing that's really odd to me is that this URL is being rewritten and, I thought, handed over to the next server, so the proxy shouldn't be involved anymore. But for whatever reason, it's still doing the slash rewrites after the initial remote page is loaded.

One thing I should mention is that this config is running on an old Apache version (1.3), so there may be some differences in config from the versions I'm more accustomed to (v2.x+), even though httpd doesn't complain at all on syntax checks or restarts. Is there a cross-version way to do this? Or maybe just a way that works in v1.3?
 
Old 12-30-2009, 09:42 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
You should probably convert it to a rewrite condition for the trailing slash rule rather than it being a rewrite rule by itself

cheers
 
Old 12-31-2009, 01:21 PM   #3
deesto
Member
 
Registered: May 2002
Location: NY, USA
Distribution: FreeBSD, Fedora, RHEL, Ubuntu; OS X, Win; have used Slackware, Mandrake, SuSE, Xandros
Posts: 448

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by kbp View Post
You should probably convert it to a rewrite condition for the trailing slash rule rather than it being a rewrite rule by itself
Thanks kdp ... which rule do you mean: the site-specific one, or the general '/' rewrite? If the '/', isn't that what the '!(/)$' condition is for? If not, please help me understand?
 
Old 12-31-2009, 05:22 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Sorry.. I wasn't reading carefully enough, apache rewrites are really easy to get wrong.

I usually turn on rewrite logging when troubleshooting :

Code:
RewriteEngine On
RewriteLog /var/log/apache/mysite_rewrite.log
RewriteLogLevel 9
If you move them around like so:
Code:
...
RewriteEngine on
RewriteLogLevel 0

# rewrite for somesite
RewriteRule ^/somesite/(.*)$ http://some.server.com/somesite/somelongpath/$1 [R=301,NC,L]

# any URL request missing a trailing slash gets one:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(/)$
RewriteRule (.*)$ $1/ [R,NC]
..does this make a difference ?
 
1 members found this post helpful.
Old 01-05-2010, 01:35 PM   #5
deesto
Member
 
Registered: May 2002
Location: NY, USA
Distribution: FreeBSD, Fedora, RHEL, Ubuntu; OS X, Win; have used Slackware, Mandrake, SuSE, Xandros
Posts: 448

Original Poster
Rep: Reputation: 31
Thanks kbp, but no, moving the rules doesn't seem to help ... it may be because I have so many other redirects going on, but moving the slash rule isn't working ...

Here's an example log entry for one image file that shows a redirect for the image file ... but I don't see an error in the entry itself, but the actual HTML renders with missing images (which still show references to "image.gif/"):
http://deesto.pastebin.com/m612bb3a8

... and here is the current config; maybe you'll see a mistake that I haven't noticed:
http://deesto.pastebin.com/m30951176
 
Old 01-05-2010, 03:19 PM   #6
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
The image listed in the log didn't get modified because it matched one of the previous rules, the 'trailing slash' rule will only affect requests that don't match any of the previous rules. Could you please provide an example url with the broken image links ?

thnx
 
1 members found this post helpful.
Old 01-05-2010, 03:41 PM   #7
deesto
Member
 
Registered: May 2002
Location: NY, USA
Distribution: FreeBSD, Fedora, RHEL, Ubuntu; OS X, Win; have used Slackware, Mandrake, SuSE, Xandros
Posts: 448

Original Poster
Rep: Reputation: 31
Thanks kbp ... sent you a PM with some URLs ... let me know if you can see where I'm screwing up?
 
Old 01-22-2010, 03:58 PM   #8
deesto
Member
 
Registered: May 2002
Location: NY, USA
Distribution: FreeBSD, Fedora, RHEL, Ubuntu; OS X, Win; have used Slackware, Mandrake, SuSE, Xandros
Posts: 448

Original Poster
Rep: Reputation: 31
Just wanted to make a quick mention that although we weren't able to pinpoint the problem with these Apache directives (bloody rewrite rules!), kbp was kind enough to get in touch with me privately and try to analyze the conf files, log data, etc. I really appreciate his help.
 
  


Reply

Tags
apache, rewriterule, slash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache trailing slash problem for multiple rewrites deesto Linux - Server 6 01-16-2011 01:01 AM
open GL displays have horizonal lines screwing up the display images Balarabay1 Linux - Software 1 09-20-2008 07:59 PM
Problem with Apache and images jc materi Linux - Networking 1 06-09-2006 07:19 PM
apache not displaying images tlgates Linux - Networking 0 01-24-2005 03:06 PM
no images on apache.. Keiseren Mandriva 0 03-08-2004 09:12 AM


All times are GMT -5. The time now is 07:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration