我尝试在URL中使用没有/ web slug的Symphony 2项目。我已将以下内容添加到我的根文件夹(localhost / subdir)中的.htaccess
文件中。
<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
以使其正常工作?
答案 0 :(得分:0)
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与数据库传递等可以访问。
web / .htaccess conf用于重写url中的app.php / app_dev.php看起来像ike:# 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>