简体   繁体   English

Symfony 2:Web服务器不会重写URL

[英]Symfony 2: The Web server doesn't rewrite the URL

when I put my web app (Symfony2) on production for this time the server doesn't rewrite (it often does) the URL and I don't know why. 当我这次将我的Web应用程序(Symfony2)投入生产时,服务器不重写(通常是重写)URL,我也不知道为什么。 I usualuse the .htaccess files in the root and in the web folder. 我通常在根目录和Web文件夹中使用.htaccess文件。

.htaccess in root: .htaccess根目录:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]

.htaccess in /web: / web中的.htaccess:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ web/$1 [QSA,L] RewriteCond%{REQUEST_FILENAME}上的RewriteEngine!-f RewriteRule ^(。*)$ web / $ 1 [QSA,L]

the following error is generated by the server: 服务器生成以下错误:

Internal Server Error 内部服务器错误

The server encountered an internal error or misconfiguration and was unable to complete your request. 服务器遇到内部错误或配置错误,无法完成您的请求。

Please contact the server administrator at webmaster@subdomaine_goes_here.domaine_goes_here.com to inform them of the time this error occurred, and the actions you performed just before this error. 请通过webmaster@subdomaine_goes_here.domaine_goes_here.com与服务器管理员联系,以告知他们该错误发生的时间以及在该错误发生之前您执行的操作。

More information about this error may be available in the server error log. 服务器错误日志中可能会提供有关此错误的更多信息。

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. 此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误错误。

You don't need .htaccess in root, you need .htaccess in your web directory and and domain should be set to point the web directory. 您在根目录中不需要.htaccess,在您的Web目录中需要.htaccess,并且应该将域设置为指向该Web目录。 Of course it can be customised but it's the best solution (php files are not accessible from browser). 当然可以对其进行自定义,但这是最好的解决方案(无法从浏览器访问php文件)。 .htaccess should point web/app.php on production .htaccess应该指向生产中的web / app.php

Whole server configuration part can be found on: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html 整个服务器配置部分可以在以下位置找到: http : //symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

successfully solve the problem by putting two .htaccess files in the projects folders (REMEMBER: I'm using a sub-domain): 通过在项目文件夹中放置两个.htaccess文件成功解决了该问题(记住:我正在使用子域):

in root /: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ web/$1 [QSA,L] 在根目录/中:RewriteEngine在RewriteCond%{REQUEST_FILENAME}上!-f RewriteRule ^(。*)$ web / $ 1 [QSA,L]

in /web folder: I keept the original .htaccess file ships with symfony 2.7 在/ web文件夹中:我保留原始的.htaccess文件与symfony 2.7一起提供

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM