首页 > 解决方案 > 如果请求 wp-admin,Apache 重写规则以停止重定向

问题描述

我在谷歌云上有一个带有 bitnami 的 apache 配置文件。我添加了一条从非 www aka example.com 重定向到www.example.com的规则。但是,我想在 /wp-admin/ 目录不重定向但留在 example.com 的规则中例外。

更多示例

  1. example.com/launch.html -> www.example.com/launch.html

  2. example.com/wp-admin/plugins -> example.com/wp-admin/plugins(保持不变)

Apache conf 文件原样

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny                          
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>

<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache2/htdocs"

RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]            
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny                          
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html
        
  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
</VirtualHost>

标签: phpwordpressapachewebserverhosting

解决方案


推荐阅读