Dot-Htaccess

Apache 2.4.12 將 Wordpress 子文件夾重定向到另一個伺服器 IP 地址

  • May 25, 2015

我在充當我網站根目錄的 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 me@example.com

  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>

最簡單的方法是添加:

Redirect permanent /forum http://otherserver

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

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

到您的 .htaccess。

引用自:https://serverfault.com/questions/694333