You are not logged in.

#1 2006-01-03 20:41:35

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

mod_rewrite, WordPress and images

Dear boffins,

On my web-server I have a dir called blog where all my blog stuff lives, mainly my WordPress installation. Within that is a sub-directory called 'images', and guess what, that's where I stick any images which I want to post on the blog.

When I'm writing a post which uses an image, i'll write '<img src="images/myimage.png">'. For the default set up where all entries have URLs like http://myblog.net/?p=24, the image will display fine on both the main front page, and when you click on the direct entry URL.

However, when I turn on a bit of the ol' mod_rewrite snizzle, images look ok on the front page (because it's a relative link) but, as I'm sure you've guessed by now, the pretty URL format of http://myblog.net/2006/1/my_cool_entry/, the relative image path is way out, and so nothing gets displayed.

mod_rewrite rules look total gibberish that I can't decipher. The rules I use are those that are generated by WordPress in the Permalinks options tab. I hoped it would take care of this.

I don't suppose any one has any suggestions to get my images to work on both the front page, and the actual entries too, without resorting to absolute URLs?

Many thanks

Offline

#2 2006-01-03 21:58:37

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: mod_rewrite, WordPress and images

arooaroo wrote:

I don't suppose any one has any suggestions to get my images to work on both the front page, and the actual entries too, without resorting to absolute URLs?

I've always just used absolute URLs for my images when using WordPress...why are you against that, if you don't mind me asking?  I'm not sure if there would be a way to specifically target just images with a mod_rewrite rule or not, but if there was, I would think it'd be fairly complex to implement.

Offline

#3 2006-01-03 22:05:54

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: mod_rewrite, WordPress and images

elasticdog wrote:

I've always just used absolute URLs for my images when using WordPress...why are you against that, if you don't mind me asking?

Because it would require me going back and fixing my img tags to be absolute. Also, should I change domain or whatever, then I don't want the hassle.

Offline

#4 2006-01-03 23:15:49

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: mod_rewrite, WordPress and images

I can help you when i get home this evening...unless someone does first.
At work right now, so I can't bust out with my mod_rewire foo skills.
wink

people would stare..


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#5 2006-01-03 23:22:12

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: mod_rewrite, WordPress and images

Good man. I'll probably be fast asleep in the Land of Nod by that time, so I'll look forward to seeing your skills tomorrow morning smile

Offline

#6 2006-01-04 03:15:09

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: mod_rewrite, WordPress and images

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}% !^/images/(.*)
RewriteRule . /blog/index.php
</IfModule>

try that for your wordpress rewrite rules..


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#7 2006-01-04 21:46:54

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: mod_rewrite, WordPress and images

Well the domain problem wouldn't be an issue if you used a link such as <code><img src="/images/example.jpg" /></code>, but you're right that mod_rewrite would be a easier fix if there are a ton of entries to go through...perhaps that could be automated in some way with a <code>mysqldump</code> and a scripting language to replace all image URLs?

Offline

#8 2006-01-04 23:32:55

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: mod_rewrite, WordPress and images

Thanks for the help Cactus, but it turns out I'm having some difficulties with WordPress. I'm still using 1.5.2.

Basically, the .htaccess doesn't seem to be read. It seems to me that WP is doing something else to create the Permalinks! Let me shed some light. Permissions for /blog/.htaccess is 600. I edit the file so that it contains the rules - no difference, I still get ?24.php type URLs. I then go into the WP Permalinks page, specify a format - click the 'update structure' button. It tells me it can't write the .htaccess file because it hasn't got permission. It then tells me what I need to copy and paste. I don't bother, yet the rules are obeyed! I check the .htaccess file: it still contains my original rules as specified by Cactus.

So, I empty the .htaccess file. It still has the permalink structure now! I go back to the options, and disable permalinks, and there we are, back the to un-pretty ?24.php URLs. WTF?!?

So, I set permissions to be 666 on .htaccess so that WP can edit it directly from the Options. I add a typical %year%/%month%... structure, hit the update button. It tells me that it has successfully updated my .htaccess. Sure enough, I check the file and it contains the new rules. Ok, I edit the file once again. I replace the generated rules with Cactus's rules. The main displays, but then I get Server Errors when I click on a permalink to one of the entries.

It's all gone Pete Tong! Where is WP getting the mod_rewrite rules from? It only seems to play ball when you use its permalinks options page, but that only sets rules the WP-way. I've disabled permalinks for now.

Offline

#9 2006-01-05 01:01:19

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: mod_rewrite, WordPress and images

hmmmm.. if you are using the wp rules engine..with "index.php" in all the urls..mine wont work..

My specified rules should work with wp 2.0.. I don't remember what the ones for wp 1.x were...


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#10 2006-01-05 01:30:15

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: mod_rewrite, WordPress and images

oh, and roo..that ruleset needs to go into the / dir's .htaccess..not the /blog dir.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#11 2006-01-05 11:07:38

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: mod_rewrite, WordPress and images

cactus wrote:

oh, and roo..that ruleset needs to go into the / dir's .htaccess..not the /blog dir.

The blog dir is a the "root" of my blog.andy-roberts.net subdomain. So is it still the case that it needs to go in the root .htaccess for andy-roberts? If so, why did WP edit the /blog/.htaccess when I gave it adequate permission?

Offline

#12 2006-01-05 15:52:26

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: mod_rewrite, WordPress and images

wait..it should work in the subdir too..disregard my previous statement roo.
wink
*blushing*


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

Board footer

Powered by FluxBB