使用 htaccess,重定向 http 或 https 域,以及任何子页面到另一台服务器上的特定页面
Using htaccess, Redirect http or https domain, and any subpage to particular page on another server
背景:
- 我们有指向新服务器的 DNS。
- Apache 服务器有一个名为 example 的目录
- 示例目录有一个用于重定向的 htaccess 文件,代码如下
问题是:我们需要它来重定向 url 的任何变体,即:http://example.com, https://example.com, http://example.com/filename.html, https://example.com/directory/filename.html,等等。 到另一台服务器上的特定页面。
到目前为止,我们有下面的代码,它适用于 https,但不适用于 http。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://differenturl/login/login.html [R=301,L]
我觉得有一个简单的答案,但似乎找不到!
**编辑:为了澄清 - 不工作,我的意思是我没有重定向到 https://differenturl/ 等...使用 http。它仅适用于 https。 http 将我路由到这一切所在的服务器的主页。该服务器的域名与上面的任何域名都不同。
如果它对 HTTP“不起作用”,则:
- 服务器配置中根本没有配置端口 80(即 HTTP)的
<VirtualHost>
容器。
或者,
- vHost:80 容器指向文件系统的不同区域,因此未处理
.htaccess
文件。
或者,
vHost:80 容器不允许 .htaccess
覆盖,因此忽略 .htaccess
文件。您需要通过在 vHost:80 容器中的适当 <Directory>
容器中设置 AllowOverride All
来配置 .htaccess
覆盖。或者简单地将所有内容重定向到 vHost:80 容器中的 HTTPS(例如 Redirect / https://example.com/
),然后允许 .htaccess
文件从 HTTPS 重定向。 (这可能是 2 次重定向,但这应该不是问题。)
或者只是在服务器配置中进行重定向(到其他服务器),根本不使用 .htaccess
。
背景:
- 我们有指向新服务器的 DNS。
- Apache 服务器有一个名为 example 的目录
- 示例目录有一个用于重定向的 htaccess 文件,代码如下
问题是:我们需要它来重定向 url 的任何变体,即:http://example.com, https://example.com, http://example.com/filename.html, https://example.com/directory/filename.html,等等。 到另一台服务器上的特定页面。
到目前为止,我们有下面的代码,它适用于 https,但不适用于 http。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://differenturl/login/login.html [R=301,L]
我觉得有一个简单的答案,但似乎找不到! **编辑:为了澄清 - 不工作,我的意思是我没有重定向到 https://differenturl/ 等...使用 http。它仅适用于 https。 http 将我路由到这一切所在的服务器的主页。该服务器的域名与上面的任何域名都不同。
如果它对 HTTP“不起作用”,则:
- 服务器配置中根本没有配置端口 80(即 HTTP)的
<VirtualHost>
容器。
或者,
- vHost:80 容器指向文件系统的不同区域,因此未处理
.htaccess
文件。
或者,
vHost:80 容器不允许
.htaccess
覆盖,因此忽略.htaccess
文件。您需要通过在 vHost:80 容器中的适当<Directory>
容器中设置AllowOverride All
来配置.htaccess
覆盖。或者简单地将所有内容重定向到 vHost:80 容器中的 HTTPS(例如Redirect / https://example.com/
),然后允许.htaccess
文件从 HTTPS 重定向。 (这可能是 2 次重定向,但这应该不是问题。)或者只是在服务器配置中进行重定向(到其他服务器),根本不使用
.htaccess
。