【问题标题】:Alternative to Apache’s .htaccess file for IIS?替代 Apache 的 .htaccess 文件用于 IIS?
【发布时间】:2017-04-14 13:44:54
【问题描述】:

我正在将 WordPress 博客从 Apache 迁移到 IIS。这只是几个星期,直到我把它换掉。但我只能访问主页。其他一切都会引发错误。

我认为我的问题出在 .htaccess 文件中:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END WordPress

对于 IIS 是否有与此等价的东西?

谢谢。

【问题讨论】:

  • 您在 Windows 上使用的是 IIS 还是 Apache?
  • 另外,它会抛出什么样的错误?
  • 使用 IIS。错误:如果我单击具有子目录的链接,例如 mysite.com/news,则会收到 404 错误。如果我在地址栏中添加 /index.php,我没有指定输入文件。

标签: iis .htaccess server-migration


【解决方案1】:

我想你会在这里找到答案 - How To Set Pretty Permalinks in Wordpress Runs On IIS 7 我想你需要在根文件夹中放置一个 web.config 文件,例如:

<?xml version="1.0"?>
<configuration>
 <system.webServer>
 <defaultDocument>
  <files>
    <remove value="index.php" />
    <add value="index.php" />
  </files>
 </defaultDocument>
<rewrite>
 <rules>
     <rule name="Main Rule" stopProcessing="true">
         <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="index.php/{R:0}" />
     </rule>
 </rules>
</rewrite>
</system.webServer>
</configuration>

【讨论】:

    【解决方案2】:

    “漂亮”的永久链接通常需要 mod_rewrite 和 IIS(常见于 Windows 服务器)不支持 mod_rewrite。

    检查 Wordpress Codex,特别是 Permalinks Without Mod Rewrite 部分,因为它包含有关您环境中永久链接的信息(下面的一些信息,请查看链接以获取完整信息,因为它是官方文档):

    如果您使用的是 IIS 7 并且拥有管理员权限 您的服务器上的权限,您可以使用 微软的 URL 重写模块 反而。虽然不完全 与 mod_rewrite 兼容,它确实 支持 WordPress 漂亮的永久链接。 安装后,打开 web.config WordPress文件夹中的文件并添加 以下规则 system.webServer 元素。

    <rewrite>
        <rules>
            <rule name="Main Rule" stopProcessing="true">
                <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="index.php" />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

      【解决方案3】:

      “漂亮”的永久链接通常需要 mod_rewrite 和 IIS(常见于 Windows 服务器)不支持 mod_rewrite。

      无论您使用的是 IIS6 还是 7,您还可以在 IIS 上使用重写引擎 - 其中许多支持 mod_rewrite 语法。
      IIRF 是一个很好的引擎,适用于 IIS6 和 7。(Vista,WS2003 , 2008)。

      【讨论】:

        【解决方案4】:

        最后安装了新的 WordPress,然后有选择地导入表格。

        问题当然是固定链接。但我发现修复它的最简单方法是使用与旧站点相同的结构永久链接(幸运的是它还没有被删除,所以我可以在管理员中找到它),然后导入除用户表之外的所有内容。

        如果您导入用户表,您将失去新设置的管理员登录名。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-07-25
          • 1970-01-01
          • 1970-01-01
          • 2014-01-06
          • 1970-01-01
          • 2012-01-30
          相关资源
          最近更新 更多