| Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-30-2009, 01:08 PM
|
#1
|
|
Member
Registered: May 2002
Location: NY, USA
Distribution: FreeBSD, Fedora, RHEL, Ubuntu; OS X, Win; have used Slackware, Mandrake, SuSE, Xandros
Posts: 448
Rep:
|
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?
|
|
|
|
12-30-2009, 09:42 PM
|
#2
|
|
Senior Member
Registered: Aug 2009
Posts: 3,497
|
You should probably convert it to a rewrite condition for the trailing slash rule rather than it being a rewrite rule by itself
cheers
|
|
|
|
12-31-2009, 01:21 PM
|
#3
|
|
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:
|
Quote:
Originally Posted by kbp
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?
|
|
|
|
12-31-2009, 05:22 PM
|
#4
|
|
Senior Member
Registered: Aug 2009
Posts: 3,497
|
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.
|
01-05-2010, 01:35 PM
|
#5
|
|
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:
|
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
|
|
|
|
01-05-2010, 03:19 PM
|
#6
|
|
Senior Member
Registered: Aug 2009
Posts: 3,497
|
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.
|
01-05-2010, 03:41 PM
|
#7
|
|
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:
|
Thanks kbp ... sent you a PM with some URLs ... let me know if you can see where I'm screwing up?
|
|
|
|
01-22-2010, 03:58 PM
|
#8
|
|
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:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:48 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|