我在核心网站-www.example.com旁边创建了一个临时wordpress网站(测试环境) - www.staging.example.com。问题是主网站www.example.com与SSL有关。因此,我无法进入临时站点。主站点内的Htaccess如下所述。它会将每个非www重定向到www,然后依次将http重定向到https。我可以在此处向我的临时站点添加例外 - www.staging.example.com (root dir: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>
我还想知道是否需要在我的暂存站点的Htaccess中放置任何内容(public_html / staging / htaccess)?
答案 0 :(得分:1)
将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