I uploaded my symfony2 project to server grove. The main page loads, but all the links are broken. I tried adding app.php to the web address. It did work, but:
我将symfony2项目上传到服务器树丛。主页面加载,但所有链接都被破坏。我尝试将app.php添加到网址。它确实有效,但是:
I have routes like this one:
我有这样的路线:
www.something.com/app.php/something
www.something.com/app.php/something
I want them to be:
我希望他们是:
www.something.com/something.
www.something.com/something。
I've been reading, and I should put some rewrite rules on the .htaccess.
我一直在阅读,我应该在.htaccess上加上一些重写规则。
I found these rules, but they don't seem to work:
我发现了这些规则,但它们似乎不起作用:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
5 个解决方案
#1
57
Try this in your .htaccess file (inside the web directory):
在你的.htaccess文件中尝试这个(在web目录中):
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_dev.php [QSA,L]
</IfModule>
#2
23
To improve upon whistlergreg's answer, I added a line so that the bundles folder is not broken. This will make sure external resources such as images are not broken.
为了改进whistlergreg的答案,我添加了一行,以便bundle文件夹不被破坏。这将确保图像等外部资源不会被破坏。
<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
RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /web/app.php [QSA,L]
RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>
#3
3
You don't have enabled rewrite module. This code is executed if mod_rewrite.c is enabled. You must only enable mod_rewrite in apache2. http://www.unixmen.com/how-to-enable-and-disable-apache-modules/
您没有启用重写模块。如果启用了mod_rewrite.c,则执行此代码。您只能在apache2中启用mod_rewrite。 http://www.unixmen.com/how-to-enable-and-disable-apache-modules/
For example in Ubuntu:
例如在Ubuntu中:
sudo a2enmod rewrite
sudo service apache2 restart
#4
0
Also, ... remember to uncomment (if commented) the apache configuration:
另外,...记得取消注释(如果注释)apache配置:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule rewrite_module libexec / apache2 / mod_rewrite.so
MacOsX
/private/etc/apache2/httpd.conf
/private/etc/apache2/httpd.conf
#5
0
You can try giving the full path to your assets(full url). I had the same issue when I deployed my first symfony application
您可以尝试提供资产的完整路径(完整网址)。我部署第一个symfony应用程序时遇到了同样的问题
My root directory (public_html folder in most of the case).htaccess file looks like this
我的根目录(大多数情况下是public_html文件夹).htaccess文件看起来像这样
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]
#1
57
Try this in your .htaccess file (inside the web directory):
在你的.htaccess文件中尝试这个(在web目录中):
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_dev.php [QSA,L]
</IfModule>
#2
23
To improve upon whistlergreg's answer, I added a line so that the bundles folder is not broken. This will make sure external resources such as images are not broken.
为了改进whistlergreg的答案,我添加了一行,以便bundle文件夹不被破坏。这将确保图像等外部资源不会被破坏。
<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
RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /web/app.php [QSA,L]
RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>
#3
3
You don't have enabled rewrite module. This code is executed if mod_rewrite.c is enabled. You must only enable mod_rewrite in apache2. http://www.unixmen.com/how-to-enable-and-disable-apache-modules/
您没有启用重写模块。如果启用了mod_rewrite.c,则执行此代码。您只能在apache2中启用mod_rewrite。 http://www.unixmen.com/how-to-enable-and-disable-apache-modules/
For example in Ubuntu:
例如在Ubuntu中:
sudo a2enmod rewrite
sudo service apache2 restart
#4
0
Also, ... remember to uncomment (if commented) the apache configuration:
另外,...记得取消注释(如果注释)apache配置:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule rewrite_module libexec / apache2 / mod_rewrite.so
MacOsX
/private/etc/apache2/httpd.conf
/private/etc/apache2/httpd.conf
#5
0
You can try giving the full path to your assets(full url). I had the same issue when I deployed my first symfony application
您可以尝试提供资产的完整路径(完整网址)。我部署第一个symfony应用程序时遇到了同样的问题
My root directory (public_html folder in most of the case).htaccess file looks like this
我的根目录(大多数情况下是public_html文件夹).htaccess文件看起来像这样
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]