I recently started consolidating all of my various standalone websites into GoMakeThings.com.
It's made managing my various stuff easier, and means that the search functionality on my site can now search across articles, podcasts, my web developer toolkit, and more.
One of the questions I've gotten from a few people about this move is what I'm doing with this old domains, and how this impacts my SEO.
- I'll keep owning those domains forever.
- I've setup redirects on the old domains that point people to the new ones.
- New projects will get spun up at GoMakeThings.com instead of on their own domain.
Today, I wanted to show you how I setup those redirects.
My sites all run on an Apache server hosted by DigitalOcean. On an Apache server, an .htaccess
file can be used to configure various server behaviors, including redirects.
If you want to redirect all pages on a site to one place, you can use the Redirect
operator.
Redirect 301 / https://gomakethings.com/toolkit/
After Redirect
, you declare, in this order…
- The response status code (
301
means "moved permanently") - The URL path to redirect from (here,
/
means the root URL) - The URL to redirect to
In my case, I wanted smart redirects that automatically sent folks from the old pages to the news ones, not just the high-level toolkit.
If you want to match paths, you can use Apache's RewriteEngine
.
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^vanillajstoolkit.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.vanillajstoolkit.com$ RewriteRule (.*)$ https://gomakethings.com/toolkit/$1 [R=301,L] </IfModule>
- First, you set the
RewriteEngine
toon
. - Next, you set the
RewriteCond
you want to match, as a regex. In my case, I'm matching against the root domain (both with and withoutwww.
), and I want to match the entire path after it (the$
). - I used two flags (
[]
). TheNC
flags tells it to ignore case when matching, andOR
tells it to match either condition. - The
RewriteRule
tells Apache where to redirect the user. In this case, togomakethings.com/toolkit/
, with the matched text appended to the end ($1
). - The
R
flag indicates the response status, and theL
flag indicates that its the last rule and theRewriteEngine
can stop parsing.
I'm using this on my Vanilla JS Toolkit and the Vanilla JS Podcast to redirect folks to specific tools and episodes.
Cheers,
Chris
Want to share this with others or read it later? View it in a browser.
0 Komentar untuk "[Go Make Things] How to setup dynamic server redirects in Apache with .htaccess"