2013-08-16 102 views
0

我想从url中删除扩展名.php,以便mysite.com/home.php可以像mysite.com/home一样工作。IIS web.config启用重写规则

我在1and1.com上托管我的网站,并询问他们是否打开了重写引擎,并且他们说,对于运行IIS 7.5的Windows服务器,它未打开,我可以打开它web.config文件中的一些代码。

我一直没有找到能够开启重写规则的代码。

下面是我试图用来重写网址的内容。但是我得到一个错误500.19。

真的有办法在web.config文件中打开重写吗?

web.config文件

<?xml version="1.0" encoding="UTF-8"?> 
<configuration>  
    <system.webServer> 
     <directoryBrowse enabled="false" /> 
     <defaultDocument> 
      <files> 
       <clear /> 
      <add value="home.php" /> 
      <add value="index.html" /> 
      </files> 
     </defaultDocument> 
     <rewrite> 
      <rules> 
       <rule name="rewrite php"> 
        <!--Removes the .php extension for all pages.--> 
        <match url="(.*)" /> 
        <conditions logicalGrouping="MatchAll"> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        <add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).php" /> 
        </conditions> 
        <action type="Rewrite" url="{R:1}.php" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration> 
+0

http://stackoverflow.com/questions/18275740/have-page-come-up-without-the-aspx可能能够使用类似的东西去除.php – sealz

回答

3

发现,1and1.com不得不重写引擎关闭的web.config文件。

但我发现我可以使用web.config文件重定向到一个主页,同时使用.htaccess文件,它的重写规则从url中删除.php扩展名。

web.config文件

<?xml version="1.0" encoding="UTF-8"?> 
<configuration>  
    <system.webServer> 
     <directoryBrowse enabled="false" /> 
     <defaultDocument> 
      <files> 
       <clear /> 
      <add value="home.php" /> 
      <add value="index.html" /> 
      </files> 
     </defaultDocument> 

    </system.webServer> 
</configuration> 

.htaccess文件

​​

两个文件都位于根。并且完美地工作。

-1

在1and1 windows主机中,它们限制了web.config中的重定向和重写规则。因此,如果您使用<rewrite>标记,则会出现应用程序级别错误。见 -

https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/aspnet-c39624/aspnet-application-restrictions-for-hosting-packages-a603259.html

https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/aspnet-c39624/permitted-webconfig-file-settings-a617208.html

所以,无论是从.htaccess文件执行或者改变您的主机。