问题原文
原帖链接 · TRiG · CC BY-SA 3.0
A site has moved from example.net to example.com/ie/en/. (In other words, it’s moved from being its own domain to being a subfolder in a larger site.) However, the page structure has also changed. I have a few pages with specific redirects. For example, example.net/packaging should redirect to example.com/ie/en/packaging-solutions/. Everything else (the homepage and all pages not specifically mentioned) should redirect to example.com/ie/en/ directly.
Here’s what I tried:
Redirect permanent /geotextiles http://www.example.com/ie/en/technical-fabrics/geosynthetics/
Redirect permanent /fibcs http://www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/
Redirect permanent /packaging http://www.example.com/ie/en/packaging-solutions/
Redirect permanent /bags-fibcs http://www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/
Redirect permanent /horticultural http://www.example.com/ie/en/technical-fabrics/agri-horti-aquaculture/
Redirect permanent /construction http://www.example.com/ie/en/technical-fabrics/construction/
Redirect permanent / http://www.example.com/ie/en/
RewriteEngine On
RewriteRule ^(.*)$ http://www.example.com/ie/en/ [R=301]
This very nearly works. The pages mentioned specifically redirect as they should; so does the homepage. However, other pages do not work. example.net/blah should redirect to example.com/ie/en/, but instead redirects to example.net/ie/en/blah. Is there any simple way to lose the page name? The new website is completely restructured, and quite simply doesn’t have equivalent pages to some of those on the old site, so redirecting to the homepage makes sense.
Taking a tip from an answer, I tried this approach:
RewriteEngine On
RewriteRule /geotextiles http://www.example.com/ie/en/technical-fabrics/geosynthetics/ [R=301,L]
RewriteRule /fibcs http://www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/ [R=301,L]
RewriteRule /packaging http://www.example.com/ie/en/packaging-solutions/ [R=301,L]
RewriteRule /bags-fibcs http://www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/ [R=301,L]
RewriteRule /horticultural http://www.example.com/ie/en/technical-fabrics/agri-horti-aquaculture/ [R=301,L]
RewriteRule /construction http://www.example.com/ie/en/technical-fabrics/construction/ [R=301,L]
RewriteRule / http://www.example.com/ie/en/ [R=301,L]
RewriteRule ^(.*)$ http://www.example.com/ie/en/ [R=301,L]
And now everything redirects to www.example.com/ie/en/. All my special cases are being ignored, despite the L flag.
已采纳解答
原帖链接 · Tero Kilkanen · CC BY-SA 3.0
You should write all your rules using RewriteRule, since those two directives are handled by different modules, and things might not work as you expect if you use both modules.
For example:
Redirect permanent /geotextiles http://www.example.com/ie/en/technical-fabrics/geosynthetics/
is like this using RewriteRule:
RewriteRule ^geotextiles http://www.example.com/ie/en/technical-fabrics/geosynthetics/ [R=301,L]
Doing this most replacement could solve your problem.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
