htaccess - wordpress 页面的子域 - 保持原始 url

htaccess - Subdomain to wordpress page - keep original url

我有一个用于我们运动俱乐部的 wordpress 网站 (example.com),我想使用不同的子域(足球、排球)来路由到它自己的页面示例。com/football;

但是 URL 应该仍然显示足球。example.com/

其他页面如/terms、/contact 或/location 都是一样的。因此,如果有请求,例如。com/terms 或 volleyball.example。com/terms 它应该全部 link 到同一页面,但保持原始 URL 及其原始子域。

我试过了:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /


RewriteCond %{HTTP_HOST} ^football.example.com [NC]
RewriteRule ^(.*) http://example.com/ [P, L]

RewriteCond %{HTTP_HOST} ^volleyball.example.com [NC]
RewriteRule ^(.*) http://example.com/ [P, L]

</IfModule>


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

我的 apache2.conf 具有此目录的以下选项

  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted

当我请求 URL 中的特定页面但 url 发生变化时,P 选项将我重定向到正确的页面;如果我不请求页面并且只使用排球。example.com 我从 Wordpress 收到未找到错误消息。

P 和 L 结合起来得到一个 500 内部服务器错误,日志文件中有以下文本

RewriteRule: bad flag delimiters
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} (football|volleyball)\.example\.com$ [NC]
RewriteRule ^(.*) http://%1.example.com/%1 [L]


</IfModule>

#BEGIN Wordpress
[original Wordpress Content]
#END Wordpress

这段代码几乎就是我想要的。如果我不请求特定页面,而是请求 volleyball.example.com,我将被重定向到 volleyball.example。com/volleyball 如果我要求 volleyball.example。com/terms 我会接受条款。