.htaccess is being forefully used for localhost

爷,独闯天下 提交于 2019-12-11 01:28:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!