onsdag den 22. juli 2009

xorg.conf revisited

A long time ago we bought a cheap LCD for our living room. A long time ago I found a way to configure one of the numerous Linux-boxes that was attached to it such that it would run with a screen resolution close to its native resolution of 1366x768. This xorg.conf file was lost along the way - and for a long time we have lived with what the EDID of the screen had to say about it: 1280x1024. For a long time we have changed the aspect ratio on all videos being played on this linux box.

Today no more!


Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0" 0 0
EndSection

Section "Module"
Load "dbe"
Load "extmod"
Load "glx"
EndSection

Section "Monitor"
Identifier "Hisense"
Modeline "1360x768" 85.500 1360 1424 1536 1792 768 771 777 795 +Hsync +Vsync
EndSection

Section "Device"
Identifier "Device0"
Driver "nvidia"
Option "ExactModeTimingsDVI" "true"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Hisense"
SubSection "Display"
Depth 24
Modes "1360x768"
EndSubSection
EndSection

tirsdag den 27. januar 2009

Symfony and mod_rewrite

I am currently working as an independent developer on two projects using Symfony. This has been a great trip into a quite huge framework - and a great experience finally getting to know mod_rewrite a little better.

The first thing was that the urls in Symfony soon become something like this:

http://hostname/appname.php/modulename/actionname/arg1/arg1value/arg2/arg2value

Which was cool, but not as cool as if I could remove the ".php", hence I came up with:

.htaccess
  # xxxx.php -> xxxx (if the file does not exist)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\./]+)/(.*) $1.php/$2 [L]


This worked just fine!

One thing I had serious issues with was non-existing static resources. It boils down to Symfony thinking that every request for http://host/xxx/yyy/zzz is a call to action "zzz" on module "yyy" in application "xxx". This is because of this rule:

.htaccess
  # no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]


In general this is perfectly smart, except when you try something along the lines of:

http://hostname/images/somefolder/mysuperimage.png (which does not exist)

Then symfony tries to execute the action "mysuperimage.png" on module "somefolder" in the application which you created first (typically called "frontend", and represented by "index.php"). This is down right annoying!

But there is an easy fix. All the php-files (two for each application, production/dev) are placed in the "web" folder directly. If all your resources are placed in subdirectories then all you have to do is tell mod_rewrite to leave these folders alone!

.htaccess
  # skip real folders
RewriteRule ^backend/.*$ - [PT]
RewriteRule ^css/.*$ - [PT]
RewriteRule ^images/.*$ - [PT]
RewriteRule ^resources/.*$ - [PT]
RewriteRule ^sfPropelPlugin/.*$ - [PT]
RewriteRule ^swf/.*$ - [PT]


In one place I had a lot of missing resources. I did not want to just give a flash-frontend a 404 so here was a quick fix for that:

.htaccess
  # Rewrite some resources to .xxx -> 404.xxx
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/(.*).png resources/404.png [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/(.*).jpg resources/404.jpg [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/(.*).flv resources/404.flv [L]