重定向';。php';通过web.config扩展到Azure中WordPress页面上的非扩展url
依赖关系:我正在Azure应用程序服务上运行WordPress站点 目标:如果有人访问:重定向';。php';通过web.config扩展到Azure中WordPress页面上的非扩展url,php,wordpress,azure,url-rewriting,web-config,Php,Wordpress,Azure,Url Rewriting,Web Config,依赖关系:我正在Azure应用程序服务上运行WordPress站点 目标:如果有人访问: example.com/my page.php 然后将它们重定向到: example.com/my page/ 或(不带反斜杠): example.com/my page 我已经到处寻找StackOverflow来找到解决方案,但没有任何特定于WordPress/Azure的解决方案,因此无法工作 通过Apache和.htaccess文件,答案很简单: # BEGIN WordPress <IfMod
example.com/my page.php
然后将它们重定向到:
example.com/my page/
或(不带反斜杠):
example.com/my page
我已经到处寻找StackOverflow来找到解决方案,但没有任何特定于WordPress/Azure的解决方案,因此无法工作
通过Apache和.htaccess
文件,答案很简单:
# 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
第一条规则通过WordPress的index.php
转发所有请求。第二条规则是我在网上找到的,可以帮助将所有以.php
结尾的请求转换为非扩展URL。它不起作用
有没有人能为这种特殊情况提供有效的解决方案?听起来您有一个适用于Apache的工作
.htaccess
文件,这样您就可以尝试参考博客来实现您的需求。要阅读博客的部分内容,您可以更轻松地使用IIS管理器的工具URL Rewrite>Import Rules>Import mod_Rewrite Rules
,将其自动转换
希望有帮助。明白了。以下是我的解决方案:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Remove any php extensions if it ends in php">
<match url="^(.*)\.php$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<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>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Remove any php extensions if it ends in php">
<match url="^(.*)\.php$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<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>