我想从url中删除index.php,我正在使用wordpress和iis7。 我该怎么做
使用此 web.config
(web.config是IIS相当于apache web服务器中的.htaccess文件,可以在根文件夹中找到。如果没有,则需要创建一个。)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<!-- Set the default document -->
<files>
<remove value="index.php" />
<add value="index.php" />
</files>
</defaultDocument>
<httpErrors errorMode="Detailed"/>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<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" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
然后在永久链接页面中,设置“自定义结构”并给出值
/%postname%/
请注意,需要安装特定于 IIS 版本的 URL 重写模块才能正常运行(感谢下面 @Spikolynn 的评论)
在您使用 Windows Azure 网站的情况下,另一个相当快速的解决方案是使用
Microsoft WebMatrix
登录您的网站并创建一个 web.config 文件 正如本文指出的那样 。这样就解决了。无需自己安装 URL Rewrite extension
或类似的东西。 MS Webmatrix 似乎很容易解决这个问题。
您可以轻松地从 WordPress URL 中删除 index.php,为此您可以遵循两种方法:
或者
#BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
如果您无权访问 .htaccess 文件,您可以使用 Yoast SEO 或 All in One SEO 等插件为您生成它。
来源:Webtalkhub