.htaccess 将子文件夹重定向到新域

.htaccess Redirect Subfolder to New Domain

我的客户想使用他们的域。com/billpay 来掩盖处理他们在线支付的公司提供给我们的 URL。我知道如果它是子域(即 billpay.theirdomain.com)可以通过 DNS 完成,但我不确定当它是上述主要 URL 的实际附属物时如何处理。我假设这可以通过 .htaccess 文件来完成。这是我现在的代码,但我收到 500 内部服务器错误:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /croutlet/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>

//301 Redirect Entire Directory
RedirectMatch 301 /billpay(.*) /http://www.google.com/

这可能不是影响 500 错误的原因,但请尝试仅使用 mod_rewrite 而不是同时使用 mod_alias(RedirectMatch 指令)和 mod_rewrite。当您有路由重写规则时,它们会相互干扰,因为两个模块都会应用于每个请求。

RewriteRule ^billpay(.*)$ http://www.google.com/ [L,R=301]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /croutlet/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>

请注意,由于重定向是 301(永久),您的浏览器将始终缓存重定向,除非您清除它。