修改现有的.htaccess,使其忽略子域

问题描述 投票:0回答:2

我有以下 .htaccess 文件,虽然我知道它远非最佳(而且可能有点令人难受) - 它只是有效。

# Prevents public viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# Custom 404 page
ErrorDocument 404 https://www.domain.com/404/

# Turn on rewriting and set rewriting base
RewriteEngine On
RewriteBase /

# Force WWW
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]+)\.([a-z]{2,4})$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# Force WWW and HTTPS
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L]

# Remove .php extension
RewriteRule ^(properties)/(all|location1|location2|location3)/(all|1|2|3|4|5|6|7|8|9)/(asc|desc) $1.php?location=$2&bedrooms=$3&sort-by=$4
RewriteRule ^(properties)/(all|location1|location2|location3)/(all|1|2|3|4|5|6|7|8|9) $1.php?location=$2&bedrooms=$3
RewriteRule ^(properties)/(all|location1|location2|location3) $1.php?location=$2
RewriteRule ^(view-property)/(.*)/(print-view) $1.php?id=$2&print=true
RewriteRule ^(view-property)/(.*)/ $1.php?id=$2
RewriteRule ^(.*)/$ $1.php

我们的新网站现已准备好推送到我们新创建的临时环境中进行测试。在本例中,它会是

staging.domain.com
,但我们在实际访问此暂存 URL 时遇到问题。

编辑 - 只是为了澄清,问题是访问

staging.domain.com
重定向到
https://www.domain.com

我们认为问题是由我们上面的重写规则引起的。我研究了一些可能的解决方案,包括向现有重写规则添加附加条件,例如:

RewriteCond %{HTTP_HOST} !^staging\.domain\.com

或添加新的条件/规则,例如:

RewriteCond %{HTTP_HOST} ^staging\.domain\.com [NC]
RewriteRule ^(.*) - [L]

但不幸的是这些都不起作用。使用

.htaccess
文件确实不是我的强项,所以如果有人可以提供任何帮助,那就太好了。

附注新网站由 Laravel 5.3 提供支持,因此当我们上线时,我将摆脱重写规则(位于底部的规则)的可怕尝试!

apache .htaccess
2个回答
1
投票

您的顶级规则必须更改为此以删除目标 URL 中的硬编码域名:

# Turn on rewriting and set rewriting base
RewriteEngine On
RewriteBase /

# Force WWW and HTTPS
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

# Remove .php extension and rest of the rewrite rules

-3
投票

Crypto.com 登录问题 已经是 crypto.com 登录用户?继续作为 crypto.com 登录问题用户。或者。电子邮件。密码。登录 忘记密码?没有帐户?立即注册。注册 Crypto.com NFT 帐户 · 连接您经过验证的 crypto.com 登录问题 · 提交申请成为创建者 Trezor suite 应用程序 移动版 Trezor Suite Lite 是一款免费应用程序,可让您同步和跟踪所有比特币和加密货币您手机上的帐户。适用于 Trezor 硬件钱包的新桌面和浏览器应用程序。 Trezor Suite 在可用性、安全性和隐私这三个关键支柱上带来了重大改进。

© www.soinside.com 2019 - 2024. All rights reserved.