Symfony2将localhost/subdir/web/app.php/action重写为localhost/subdir/action
我尝试在URL中使用我的Symphony 2项目而没有/ web slug。我已将以下内容添加到我的根文件夹(localhost/subdir)中的.htaccess
文件中。Symfony2将localhost/subdir/web/app.php/action重写为localhost/subdir/action
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^web/app_dev.php - [L]
RewriteRule ^web/app.php - [L]
# Fix the bundles folder
RewriteCond %{HTTP_HOST} ^localhost/subdir/$
RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^localhost/subdir/$
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /web/app.php [QSA,L]
RewriteRule ^(.*)$ web/app_dev.php [QSA,L]
</IfModule>
这个脚本加载我的网页,但没有得到任何/web/bundle/mybundle/javascript/
,/images/
,或/css/
文件。这些给我一个404错误。因为在<head>
标签中,它表示/bundle/mybundle/javascript/
没有/web
前缀。在web-profiler,调试工具栏等上也是如此。
如何修复我的.htaccess
以使其工作?
web /文件夹是根web目录 所以你有一个配置错误,告诉你的apache有web作为文档根。在httpd.conf中。如:
<VirtualHost *:80>
ServerName name.localhost.com
DocumentRoot "/Projects/name/web"
<Directory "/Projects/name/web">
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
否则例如您的parameters.yml与数据库传递等可以访问。
用于重写app.php/app_dev.php的URL可能看起来IKE网/的.htaccess的conf:
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
对不起,但我不想通过httpd.conf来做到这一点,因为我将这个文件夹上传到域文件夹,该项目将通过www.site.com/project访问 – 2015-03-02 08:51:13
本网站有关的编码,而不是有关服务器的配置,你应该尝试另一种如http: //serverfault.com/ – pbenard 2015-03-02 08:34:24