Rewrite both domain and path

2019-05-30 07:22发布

I want to redirect one specific url like:

www.example.com/test/ex.gif

to

static.example.com/ex.gif

How can i do this in .htaccess?

2条回答
smile是对你的礼貌
2楼-- · 2019-05-30 07:36

Try this mod_rewrite rule:

RewriteEngine on
RewriteRule ^test/(.*) http://static.example.com/$1

Or this mod_alias directive:

Redirect /test/ http://static.example.com/
查看更多
祖国的老花朵
3楼-- · 2019-05-30 07:50

From the top of my head:

RewriteRule ^http://www.example.com/test/ex.gif$ http://static.example.com/ex.gif [NC,R=301]

or to any file in test:

RewriteRule ^http://www.example.com/test/(.*)$ http://static.example.com/$1 [NC,R=301]

Corrected after advice from Mr. Berardi

查看更多
登录 后发表回答