Mobile app version of vmapp.org
Login or Join
Reiling115

: How do I do a catch-all .htaccess redirect? 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

@Reiling115

Posted in: #301Redirect #Htaccess

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 www.example.com/ie/en/technical-fabrics/geosynthetics/ Redirect permanent /fibcs www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/ Redirect permanent /packaging www.example.com/ie/en/packaging-solutions/ Redirect permanent /bags-fibcs www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/ Redirect permanent /horticultural www.example.com/ie/en/technical-fabrics/agri-horti-aquaculture/ Redirect permanent /construction www.example.com/ie/en/technical-fabrics/construction/ Redirect permanent / www.example.com/ie/en/
RewriteEngine On
RewriteRule ^(.*)$ 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 www.example.com/ie/en/technical-fabrics/geosynthetics/ [R=301,L]
RewriteRule /fibcs www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/ [R=301,L]
RewriteRule /packaging www.example.com/ie/en/packaging-solutions/ [R=301,L]
RewriteRule /bags-fibcs www.example.com/ie/en/packaging-solutions/fibc-filling-solutions/ [R=301,L]
RewriteRule /horticultural www.example.com/ie/en/technical-fabrics/agri-horti-aquaculture/ [R=301,L]
RewriteRule /construction www.example.com/ie/en/technical-fabrics/construction/ [R=301,L]
RewriteRule / www.example.com/ie/en/ [R=301,L]
RewriteRule ^(.*)$ www.example.com/ie/en/ [R=301,L]


And now everything redirects to example.com/ie/en/. All my special cases are being ignored, despite the L flag.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Reiling115

1 Comments

Sorted by latest first Latest Oldest Best

 

@Si4351233

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 www.example.com/ie/en/technical-fabrics/geosynthetics/

is like this using RewriteRule:

RewriteRule ^geotextiles www.example.com/ie/en/technical-fabrics/geosynthetics/ [R=301,L]


Doing this most replacement could solve your problem.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme