Apache 2.4.12 将 Wordpress 子文件夹重定向到另一个服务器 IP 地址

Apache 2.4.12 将 Wordpress 子文件夹重定向到另一个服务器 IP 地址

我在 laravel 中运行 wordpress民众文件夹,该文件夹充当我的站点的根目录。当访问以下子文件夹时,如何重定向到另一个服务器 IP 地址,即 (xx.xx.xx.xxx):example.com/forum

另一台服务器运行 nginx,以论坛作为唯一站点。

以下是我为该网站配置的 apache vhost:

/etc/apache2/sites-available/example.conf

<VirtualHost *:80>
   ServerName example.com
   ServerAdmin [email protected]

   DocumentRoot /var/www/example

   RewriteEngine on
   ProxyRequests off

   #Redirect all HTTP requests to HTTPS
   RewriteCond %{SERVER_PORT} 80
   RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

   #Redirect forum subdirectory requests to forum server
   RewriteRule ^/forum$ https://example.com/forum/ [R] [L]   
   RewriteRule ^/forum/(.*) http://xx.xx.xx.xxx/$1 [P]

   <Directory /var/www/example>
     AllowOverride all  
   </Directory>
</VirtualHost>

应用.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase /


    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_URI} ^/(live|api|auth|_debugbar)$
    RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

    RewriteCond %{REQUEST_URI} ^/(live|api|auth|_debugbar)/.*
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ laravel.php [L]

    # Handle Front Controller...
    RewriteRule ^index\.php$ - [L]

    #admin panel route
    RewriteRule ^([_0-9a-zA-Z-]+/)?admin-panel/(.*) $1wp-admin/$2?%{QUERY_STRING} [L]
    RewriteRule ^login(.*) wp-login\.php/$1?%{QUERY_STRING} [L]

    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
</IfModule>

答案1

最简单的方法是添加:

Redirect permanent /forum http://otherserver

到你的 apache vhost 配置中,或者添加:

RewriteRule ^/forum(.*)$ http://otherserver/$1 [R=301,NC,L]

到您的.htaccess。

相关内容