Redirect main website to /blog

时间:2015-07-28 15:48:11

标签: html mod-rewrite redirect nginx

Hello I have a website with image links like this:

<img src="/flower.jpg"/>

I have a task to change the website path from www.domain.com to www.domain.com/blog. as www.domain.com will be used for a different site.

I am handling the redirect with nginx so www.domain.com/blog loads up the new website but the assets and images are not loading obviously because the links like <img src="/flower.jpg"/> are searching for images at :

www.domain.com/flower.jpg

whereas the image is available at

www.domain.com/blog/flower.jpg

Now I dont want to change the paths everywhere in the code. whats the best way to achieve what I need.

2 个答案:

答案 0 :(得分:0)

I just re-read your question and realised you've already moved your image files.

If you're using Apache you can try setting up a virtual host for you /blog directory, and set DocumentRoot in the config?

Otherwise I'm afraid you've got a lot of path adjusting to do in your code.

答案 1 :(得分:0)

我认为您可以选择locationrewrite

location - 方法:

location ~ /[^/]*.jpg {
  root /your/images/directory;
}

rewrite - 方法:

rewrite ^/([^/]*)\.jpg$ /blog/$1.jpg;