问题
I am using wamp-server as on localhost with a virtual host named www.xyz.com
i have a deployment service set through git which deploys code to server on www.xyz.in
This is my .htaccess code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
The above code will make your domain to add https
prefix
The problem with this code is that on server
the code works perfect bu on localhost
also it works like https:// www.xyz.com
, but on localhost
there is no such https
thing. So is there any solution to this code that it should avoid putting https
as a prefix on localhost
and work as it is on online server
.
I am expecting something like this from the above code:
1.) If I call the URL on localhost (www.xyz.com) - It should be as it is like (www.xyz.com
)
2.) If I call URL on server (www.xyz.in
or xyz.in
) - It should be like (https://www.xyz.in
)
Any helps appreciated.
回答1:
Add this after RewriteEngine on
:
RewriteCond %{HTTP_HOST} !=localhost
来源:https://stackoverflow.com/questions/42016986/htaccess-is-being-forefully-used-for-localhost