Scenario
I’m moderating a website that has moved to a WordPress based setup, but without access to all the administration tools in WordPress (it’s externally hosted/managed), but I do have access to the htaccess file. Now, there’s two things I need to do:
- Redirect the old pages to the new url structure.
- Redirect all www calls to non-www.
The challenge
I would however like to accomplish this with:
- Fewest possible redirects per call (preferably only 1).
- With limited rule duplication.
- Be somewhat readable (not just one inline Regex handling it all).
- All edited in the htaccess alone.
What is giving me a hard time, is keeping the redirects to a minimum when it is both an old url, and prefixed with www as well.
My next biggest problem is, that I would like to use a rewrite map, but it seems you have to load something externally, rather than defining a dictionary in the htaccess file which is what I would prefer.
Further details
- I’m no expert at using the Rewrite Engine so I might be missing a simple solution here.
- The old website was structured simply with
/index.php?page=<pageName>. - The new website uses seo-friendly urls
/a-new-url-example/. - Two examples could be:
- from
mydomain.com/index.php?page=bootstomydomain.com/boots/ - from
www.mydomain.com/index.php?page=shoestomydomain.com/shiny-shoes/(some kind of map is needed to handleshoes->shiny-shoes)
- from
- The current setup on my own computer does not allow me to test it locally (having a lot of conflicts with other projects), so currently I am testing the setup with http://htaccess.madewithlove.be/.
- Current content of the htaccess file (on pastebin, as the code kept getting interpreted as something else here).
I hope this doesn’t clash with your existing rules inside htaccess, as you have provided that.