Rewriting subdomain for local environment via htaccess

情到浓时终转凉″ 提交于 2019-12-12 01:43:51

问题


I need to rewrite subdomain for local environment using htaccess.

I have enabled virtual host in local and its working.

Rewrite

<link href="http://cdn.example.com/css.css" rel="stylesheet" type="text/css" />

to

<link href="http://cdn.localhost/css.css" rel="stylesheet" type="text/css" />

I am trying this way but its not working

Rewritecond %{HTTP_HOST} ^cdn.example.com [NC]
Rewriterule ^(.*)$ cdn.localhost/$1 [L,NC,QSA]

I just need to rewrite http://cdn.example.com to http://cdn.localhost

http://localhost is loacted in D:\wamp\www\example

http://cdn.localhost is loacted in D:\wamp\www\cdn

Please see and suggest any possible way to do this

Thanks.


回答1:


You're missing http:// in your target URI and R flag will also be implied once you use http:// in target URL.

Following rule should work:

Rewritecond %{HTTP_HOST} ^cdn\.example\.com$ [NC]
Rewriterule ^ http://cdn.localhost%{REQUEST_URI} [L,R]


来源:https://stackoverflow.com/questions/24096291/rewriting-subdomain-for-local-environment-via-htaccess

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