I have a symfony2 project developed on a linux server and have migrated it (unfortunately!) to a windows server for reasons outside of my control. This all works as it should except for the url rewriting. I tried using the IIS URL Rewrite Module but it failed when converting most of the rules (and stupidly i didn't save a list of which ones it failed on).
我有一个在Linux服务器上开发的symfony2项目,并且由于我无法控制的原因将其迁移到Windows服务器(不幸!)。除了url重写之外,这一切都正常。我尝试使用IIS URL重写模块但是在转换大多数规则时失败了(而且我没有保存它失败的列表)。
It mostly works fine but the app.php is still present at the start of all urls which it shouldn't be. So the urls are domain.com/app.php/correct/path when they should be domain.com/correct/path
它大部分工作正常,但app.php仍然存在于所有url的开头,它不应该存在。所以网址是domain.com/app.php/correct/path,它们应该是domain.com/correct/path
Unfortunately i rarely use windows servers and am not good at the web.config syntax so if anyone could suggest what is missing to remove the app.php from the start of all urls on the windows server then that would be greatly appreciated!
不幸的是我很少使用Windows服务器,并且不擅长web.config语法,所以如果有人可以建议从Windows服务器上的所有网址的开头删除app.php缺少什么,那将非常感谢!
The original .htaccess file is:
原始.htaccess文件是:
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]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
The converted web.config file is currently:
转换后的web.config文件目前是:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url=".?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks very much!
非常感谢!
Dave
戴夫
2 个解决方案
#1
4
Have just had this same issue while setting up symfony2 on a Windows server using IIS7.5. The trick is to go into you web site management section. Look for 'url rewrite', look for 'Import Rules'(somewhere on the right). Then on the new dialogue browse for your .htaccess file in 'SymfonyProject/web/' by default. IIS will throw an error for the trailing slash rule so delete that (Everything seems to work fine without it) and press apply. Viola no app.php.
使用IIS7.5在Windows服务器上设置symfony2时遇到同样的问题。诀窍是进入你的网站管理部分。寻找'url rewrite',寻找'Import Rules'(在右边的某个地方)。然后在新对话框中默认浏览“SymfonyProject / web /”中的.htaccess文件。 IIS将为尾部斜杠规则抛出一个错误,因此删除它(如果没有它,Everything似乎工作正常)并按下apply。 Viola没有app.php。
Be sure to add app.php to your list of default pages also.
请务必将app.php添加到默认页面列表中。
I did the above using the standard htaccess file shipped with Symfony2.
我使用Symfony2附带的标准htaccess文件完成了上述操作。
EDIT As Requested Below
In the Import Dialog I have:
在导入对话框中,我有:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / <-This line needs deleting as IIS states "This directive was not converted because it is not supported by IIS: RewriteBase "
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
So the begining of my web.config looks like this:
所以我的web.config的开头看起来像这样:
<defaultDocument enabled="true">
<files>
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Also I have set my web directory as my root directory.
我还将我的web目录设置为我的根目录。
Hope this helps. Doug.
希望这可以帮助。道格。
#2
1
I know this is an old question but today i had the same problem and i searched everywhere and took me a lot of time to fix it by replace the .htaccess file in web directory to web.config file with this content hope this will help some one .
我知道这是一个老问题,但今天我遇到了同样的问题,我在各处搜索并花了很多时间来修复它,将web目录中的.htaccess文件替换为web.config文件,希望这有助于一些一个。
<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Symfony Front Controller" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
#1
4
Have just had this same issue while setting up symfony2 on a Windows server using IIS7.5. The trick is to go into you web site management section. Look for 'url rewrite', look for 'Import Rules'(somewhere on the right). Then on the new dialogue browse for your .htaccess file in 'SymfonyProject/web/' by default. IIS will throw an error for the trailing slash rule so delete that (Everything seems to work fine without it) and press apply. Viola no app.php.
使用IIS7.5在Windows服务器上设置symfony2时遇到同样的问题。诀窍是进入你的网站管理部分。寻找'url rewrite',寻找'Import Rules'(在右边的某个地方)。然后在新对话框中默认浏览“SymfonyProject / web /”中的.htaccess文件。 IIS将为尾部斜杠规则抛出一个错误,因此删除它(如果没有它,Everything似乎工作正常)并按下apply。 Viola没有app.php。
Be sure to add app.php to your list of default pages also.
请务必将app.php添加到默认页面列表中。
I did the above using the standard htaccess file shipped with Symfony2.
我使用Symfony2附带的标准htaccess文件完成了上述操作。
EDIT As Requested Below
In the Import Dialog I have:
在导入对话框中,我有:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / <-This line needs deleting as IIS states "This directive was not converted because it is not supported by IIS: RewriteBase "
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
So the begining of my web.config looks like this:
所以我的web.config的开头看起来像这样:
<defaultDocument enabled="true">
<files>
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Also I have set my web directory as my root directory.
我还将我的web目录设置为我的根目录。
Hope this helps. Doug.
希望这可以帮助。道格。
#2
1
I know this is an old question but today i had the same problem and i searched everywhere and took me a lot of time to fix it by replace the .htaccess file in web directory to web.config file with this content hope this will help some one .
我知道这是一个老问题,但今天我遇到了同样的问题,我在各处搜索并花了很多时间来修复它,将web目录中的.htaccess文件替换为web.config文件,希望这有助于一些一个。
<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Symfony Front Controller" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>