Symfony - Symlink to Controller to remove .php Extension from Url
Morning, I have been working on this problem for a few days and cannot resolve it.
Http Stack: nginx 1.0.4, apache 2.2.3, symfony 1.4.11
In my web directory I have a symlink to my backend controller, so I can use urls without the .php extension, for example: mysite.com/be_dev.php = mysite.com/be_dev
After some googling I noticed there are a myriad of ways to do it, but the approach I found to be the most elegant was to use the apache with ForceType directives. Without this directive in place, when I use the symlink in the url it simply displays the php code, but when I put the ForceType directives in place it parses the php as expected.
The one problem I am having now, is that when I go through the symlink it treats the symlink as the webroot. So file are being served from /be_dev/sf/sf_web_debug/images/* vs /sf/sf_web_debug/images/*. If I go through be_dev.php then everything works as expected.
I have tried various rewrite rules to remove the /be_dev from the path so it would be served from / as mentioned above, but can't nail it down.
I am posting relevant snippets of the config files.
Thanks in advance.
/usr/local/nginx/etc/nginx.conf
...
server {
...
loca开发者_如何学Pythontion /sf/ {
root /home/websrc/projects/app/app1/current/framework/data/web;
}
...
}
...
/etc/httpd/conf/vhost.d/10_symfony.conf
<FilesMatch "^(fe|be)?(_dev)?$">
ForceType application/x-httpd-php
</FilesMatch>
/etc/httpd/conf/vhost.d/999_default.conf
Listen 3001
NameVirtualHost localhost:3001
<VirtualHost localhost:3001>
SetEnv SERVICECLASS dev
SetEnv SERVICEAPP app1
ServerName myhost.*.mydomain.lan
ServerAlias myhost.*.mydomain.com
ServerAdmin systems@mydomain.com
VirtualDocumentRoot /home/%2/projects/app/app1/current/code/web
<Directory "/home/*/projects/app/app1/current/code/web">
AllowOverride none
Options FollowSymLinks
RewriteEngine on
RewriteOptions inherit
#RewriteCond %{REQUEST_URI} ^/be_dev/.* [NC]
#RewriteRule ^/be_dev/(.*) /$1 [L,NC,PT]
#RewriteRule be_dev$ /$1 [L]
######
# Symfony rules
######
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule /^(be_dev)$ /$1.php [L]
######
</Directory>
LogLevel debug
CustomLog /var/log/httpd/app1.dev.access.log combined
ErrorLog /var/log/httpd/app1.dev.error.log
RewriteLog /var/log/httpd/app1.dev.rewrite.log
RewriteLogLevel 9
</VirtualHost>
Update @ 6.13.2011 Still no luck in figuring this one out, any help is appreciated.
Update @ 6.15.2011 Finally got it! Posted on my blog @ http://melikedev.com/2011/06/15/symfony-remove-php-from-controller-using-symlink/
Finally found out the reason why I couldn't remove the .php from controller, after some digging around I found that I had to override a 'request' setting in the /apps//config/factories.yml file. The full answer can be found on my blog @ http://melikedev.com/2011/06/15/symfony-remove-php-from-controller-using-symlink/, the short answer is given below.
# /path/to/symfony/apps/<app>/config/factories.yml
# If you don't already have the following activated you will need to make sure it's active under the 'all' directive
all:
...
request:
class: sfWebRequest # if you are using custom class be sure to replace this with your custom class name
param:
logging: %SF_LOGGING_ENABLED%
path_info_array: SERVER
path_info_key: PATH_INFO
relative_url_root: "" # <---This is what I needed to add
...
精彩评论