网址自动重定向 [英] URL Auto-Redirection
问题描述
我最近搬到我的主要网站到一个新的文件夹:
该网站是 www.example.com
该网站现在是在 www.example.com/website
我的问题是,很多在旧网站的链接是直接链接(而不是相对),即 www.example.com/documents/example.pdf
这是一个问题,因为相同的PDF现在是在 www.example.com/website/documents/example.pdf
有没有办法拦截到 www.example.com / $ C $请求从
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屋!