[英]Symfony2 rewrite localhost/subdir/web/app.php/action to localhost/subdir/action
我嘗試在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/
files。 這些給我一個404錯誤。 因為在<head>
標簽中它表示/bundle/mybundle/javascript/
沒有/web
前綴。 web-profiler,調試工具欄等也是如此。
如何修復我的.htaccess
才能使其正常工作?
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與數據庫傳遞等可以訪問。
用於重寫url中的app.php / app_dev.php的web / .htaccess conf可能看起來像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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.