在 Htaccess 中为暂存站点设置异常

Making Exception in Htaccess for staging site

我制作了一个暂存 wordpress 站点(测试环境)- www.staging.example.com 除了核心站点 -www.example.com。问题是主站点 www.example.com 与 SSL 绑定。因此,我无法到达临时站点。下面提到了主站点内的 Htaccess。它会将每个非 www 重定向到 www,然后依次将 http 重定向到 https。我可以在我的暂存站点中添加一个例外吗- www.staging.example.com (根目录:public_html/staging/)。我还想只允许我自己的 ip 访问这个暂存站点,这样其他人就无法访问。

<IfModule mod_rewrite.c>
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

我还想知道是否需要在暂存站点 (public_html/staging/htaccess) 的 Htaccess 中添加任何内容?

将 root .htaccess 更改为:

RewriteEngine On

# add www and http->https except for staging site    
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(?:www\.)?staging\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

里面public_html/staging/.htacces有这行只允许你的IP访问:

Order Deny,Allow
Deny from all
Allow from 10.168.0.101