Symfony 生产路由问题
Symfony production routing issue
我以这种方式配置了我的虚拟主机 (apache2):
<VirtualHost *:80>
ServerAdmin info@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/public_html/web
<Directory /var/www/mysite.com/public_html/web>
Require all granted
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我可以看到主页和资源,但看不到其他路由。
如果我将文档根目录更改为:
<VirtualHost *:80>
ServerAdmin info@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/public_html/web/app.php
<Directory /var/www/mysite.com/public_html/web/app.php>
Require all granted
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在我可以看到所有路线但看不到资产...
如何设置虚拟主机以查看所有路线和资产?
<VirtualHost *:80>
ServerName test.io
DocumentRoot "your_project_path/web"
RewriteRule ^/?(.*) http://test.io/app.php [R,L]
<Directory "your_project_path/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /app.php [NC,L]
</Directory>
</VirtualHost>
同时检查 web/.htaccess
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}:: ^(/.+)/(.*)::$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
还使用此注释将所有路由转储到 apache php app/console router:dump-apache
我以这种方式配置了我的虚拟主机 (apache2):
<VirtualHost *:80>
ServerAdmin info@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/public_html/web
<Directory /var/www/mysite.com/public_html/web>
Require all granted
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我可以看到主页和资源,但看不到其他路由。
如果我将文档根目录更改为:
<VirtualHost *:80>
ServerAdmin info@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/public_html/web/app.php
<Directory /var/www/mysite.com/public_html/web/app.php>
Require all granted
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在我可以看到所有路线但看不到资产...
如何设置虚拟主机以查看所有路线和资产?
<VirtualHost *:80>
ServerName test.io
DocumentRoot "your_project_path/web"
RewriteRule ^/?(.*) http://test.io/app.php [R,L]
<Directory "your_project_path/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /app.php [NC,L]
</Directory>
</VirtualHost>
同时检查 web/.htaccess
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}:: ^(/.+)/(.*)::$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
还使用此注释将所有路由转储到 apache php app/console router:dump-apache