Hi
I thought I should enable beautiful urls on the sites I create, so I started using them in ‘development’.
This doesn’t always work as smooth as one would expect, and it does require some fixes here and there in the way urls are created or used.
Maybe some of you can share experience with regards how to make the configuration of the urlManager more waterproof. In particular - a nice "test case", - there is the TranslaterPhpMessage extension which breaks with the following configuration.
Here is an example of a URL coming from the use of the extension:
http://example.com/TranslatePhpMessage/translate/edit/path/%2Fvar%2Fwww%2Fexample.com%2Fprotected%2F.%2Fmessages
which results in a 404 generated by Apache:
The requested URL /TranslatePhpMessage/translate/edit/path//var/www/example.com/protected/./messages was not found on this server.
When I truncate the url to:
http://example.com/TranslatePhpMessage/translate/edit/path/
I get an error generated from Yii.
So this can likely be fixed (partl) by changing the .htaccess.
Here is the configuration:
Inside config.php/main.php configuration:
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
''=>'',
),
),
The .htaccess:
<IfModule mod_headers.c>
Header set Cache-Control "no-transform"
</IfModule>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php [L]