网址自动重定向 [英] URL Auto-Redirection

查看:159
本文介绍了网址自动重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近搬到我的主要网站到一个新的文件夹:
该网站是 www.example.com
该网站现在是在 www.example.com/website

我的问题是,很多在旧网站的链接是直接链接(而不是相对),即 www.example.com/documents/example.pdf

这是一个问题,因为相同的PDF现在是在 www.example.com/website/documents/example.pdf

有没有办法拦截到 www.example.com / www.example.com/website 去C>并添加 /网站/ 的一部分吗?

想知道,如果这可以通过一的.htaccess规则

解决方案

 的RewriteCond%{REQUEST_URI}!^ /网站/
重写规则^ * $ http://www.example.com/website%{REQUEST_URI} [R = 301,L]
 

小记:我建议用302 code进行测试,当你感到满意的结果改变它(当然,在需要时),以301。究其原因 - 现代浏览器都缓存301重定向..所以它可能工作了,但你仍然可以看到缓存的结果

I recently moved my main website into a new folder:
The websites was in www.example.com.
The website is now in www.example.com/website

My problem is that alot of the links in the old site were direct links (not relative) ie www.example.com/documents/example.pdf

This is a problem because the same pdf is now in www.example.com/website/documents/example.pdf

Is there a way to intercept requests going from www.example.com/website to www.example.com/ and add the /website/ part on?

Wondering if this can be accomplished with a .htaccess rule

解决方案

RewriteCond %{REQUEST_URI} !^/website/
RewriteRule ^.*$ http://www.example.com/website%{REQUEST_URI} [R=301,L]

Small note: I suggest using 302 code for testing and when you are happy with results change it to 301 (where required, of course). The reason -- modern browsers do cache 301 redirects .. so it may work already, but you still may see cached result.

这篇关于网址自动重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆