非 www.htaccess

非 www.htaccess

即将https://www.example.com/about总是导致https://www.example.com/

我如何在强制执行时停止此操作https://www.example.com/


非 www.htaccess

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1

网页配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
    <handlers>
      <remove name="UrlRoutingHandler" />
    </handlers>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
      <remove fileExtension=".otf" />
      <remove fileExtension=".svg" />
      <remove fileExtension=".eot" />
      <remove fileExtension=".woff" />
      <remove fileExtension=".mp4" />
      <remove fileExtension=".ogv" />
      <remove fileExtension=".webm" />
      <remove fileExtension=".js" />
      <remove fileExtension=".css" />
      <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
      <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
      <mimeMap fileExtension=".webm" mimeType="video/webm" />
      <mimeMap fileExtension=".otf" mimeType="font/opentype" />
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
      <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
      <mimeMap fileExtension=".js" mimeType="text/javascript" />
      <mimeMap fileExtension=".css" mimeType="text/css" />
    </staticContent>
<rewrite>
  <rules>
                <rule name="CanonicalHostNameRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://www.example.com/{R:1}" />
                </rule>
    <rule name="Redirect to www" enabled="false" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example.com$" />
      </conditions>
      <action type="Redirect" url="{MapProtocol:{HTTPS}}://www.hotspringsscooter.com/{R:1}" />
    </rule>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^www\." ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://www.{HTTP_HOST}{URL}{R:1}" redirectType="Permanent" />
                </rule>
                <rule name="Imported Rule 2">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTPS}" pattern="off" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{URL}{R:1}" redirectType="Found" />
                </rule>
  </rules>
  <rewriteMaps>
    <rewriteMap name="MapProtocol">
      <add key="on" value="https" />
      <add key="off" value="http" />
    </rewriteMap>
  </rewriteMaps>
</rewrite>
<httpRedirect enabled="false" destination="" httpResponseStatus="Permanent" />
        <httpErrors>
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="https://www.example.com" responseMode="Redirect" />
        </httpErrors>
  </system.webServer>
</configuration>

答案1

http://codex.wordpress.org/Using_Permalinks#Permalinks_without_mod_rewrite

通过 Azure 虚拟机在 IIS 上使用 Wordpress 需要以下代码来实现永久链接 URL,例如example.com/about


添加到 Web.Config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress Rule" stopProcessing="true">
<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>

C:/inetpub/.user.ini

 cgi.fix_pathinfo = 1
 cgi.force_redirect = 0

相关内容