我刚刚创建了我的第一个Symfony2项目。但是URL中的"/web/app_dev.php“部分让我很恼火。在没有虚拟主机的情况下,应该可以做到这一点。
但是当我通过.htaccess尝试时,我总是收到路由错误,并且"web/“总是被添加到url中……
编辑:整个项目也在一个名为"symfonyTest“的子目录中。演示页面的网址是"http://localhost/symfonyTest/web/app_dev.php/demo/“,应该变成"http://localhost/symfonyTest/demo/"。链接也应该有这样的语法。这是可能的吗?”
发布于 2012-03-12 23:12:34
Symfony2提供了一个内置的调试模式,当你使用app_dev.php访问url时就会使用这个模式。调试模式的缓存比生产模式少得多,生产模式可以通过将浏览器定向到url来访问,但省略了app_dev.php。如果访问这个url不起作用,那么它可能意味着你需要清除你的生产缓存。
要清除缓存,请将终端(命令控制台)定向到Symfony项目的根目录。在此处键入以下命令:
php app/console cache:clear --env=prod --no-debug
根据Symfony 3中下面的评论,这已经移动了:
php bin/console cache:clear --env=prod --no-debug
这应该会清除您的产品缓存,并允许您在没有app_dev.php的情况下访问urls。
至于url的web部分。删除它的最简单方法是将项目的web根目录设置为web文件夹。最好在apache中使用虚拟主机来实现这一点,但是也有一些方法可以通过htaccess来实现。
此链接说明如何使用htaccess文件更改webroot。http://kb.siteground.com/how_to_change_my_document_root_folder_using_an_htaccess_file/
希望这能有所帮助!
发布于 2012-09-03 02:25:19
<VirtualHost *:80>
DocumentRoot "path_to_symfonyTest/web"
ServerName "symfonyTest"
<Directory "path_to_symfonyTest/web">
DirectoryIndex app_dev.php
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
RedirectMatch permanent ^/app_dev\.php/(.*) /$1
</Directory>
</VirtualHost>
这是我httpd.conf的一部分
发布于 2013-06-04 18:11:01
我以前也有这个问题,请看一下我的配置并尝试一下
在我的.htaccess中:
大家好,我也一直有这个问题。似乎“股票”.htaccess才是问题所在。我已经在我的环境中解决了这个问题,下面是我的.htaccess和注释:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app_dev.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_dev.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>
在我的/etc/apache2/site中的"symfony“条目中-可用:
<VirtualHost 127.0.1.15>
ServerAdmin webmaster@localhost
ServerName symfony
DocumentRoot /var/www/Symfony/web
DirectoryIndex app.php
<Directory /var/www/Symfony/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
https://stackoverflow.com/questions/9669458
复制相似问题