Rewriting subdomain for local environment via htac

2019-09-15 05:56发布

问题:

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]