我有Windows托管和网站是在PHP。所以我问托管公司我在哪里可以找到.htaccess文件。并且他们说Windows托管中没有.htaccess文件我必须使用web.config文件来进行网站配置。
我在web.config上尝试了这个简单的代码但是我得到了500 - 内部服务器错误。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
</system.web>
<rewrite>
<rule name="rule 1c" stopProcessing="true">
<match url="^([a-zA-Z]+)$" />
<action type="Rewrite" url="/index.php?category={R:1}" appendQueryString="true" />
</rule>
</rewrite>
</configuration>
答案 0 :(得分:0)
这是我用来隐藏index.php的web.config,希望这会有所帮助。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect index.php" stopProcessing="true">
<match url="index\.php/(.*)" />
<action type="Redirect" url="\?{R:1}" appendQueryString="false" />
</rule>
<rule name="Rewrite index.php">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
答案 1 :(得分:0)
这是代码
当我写作时它的工作:mysite.com/sport(mysite.com/index.php?category=sport),mysite.com/clothes(mysite.com/index.php?category=clothes)等。
但是当我写成mysite.com/index时,它被视为mysite.com/index.php?category=index
<rule name="Catagary" stopProcessing="true">
<match url="^([a-zA-Z]+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/index.php?category={R:1}" appendQueryString="true" />
</rule>
<rule name="Gallery" stopProcessing="true">
<match url="^([a-zA-Z0-9_-]+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="gallery.php?id={R:1}" appendQueryString="true" />
</rule>
<rule name="RewritePHP">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>