在 Htaccess 中为暂存站点设置例外



我做了一个暂存的wordpress网站(测试环境(-www.staging.example.com 与核心网站一起 www.example.com.问题是主站点 www.example.com 与SSL绑定。因此,我无法到达暂存站点。主站点内的 Htaccess 如下所述。它将每个非 www 重定向到 www,然后依次将 http 重定向到 https。我可以在这里向我的暂存站点添加一个例外吗 - www.staging.example.com(根目录:public_html/暂存/(。我还希望仅允许我自己的 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>

我还想知道我是否需要在我的登台站点的 Htaccess 中放置任何东西(public_html/暂存/htaccess(?

将你的根 .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

最新更新