Skip to content

Instantly share code, notes, and snippets.

@jerrickhakim
Created March 21, 2018 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerrickhakim/b0b3bd279e7c996a567a03ddd94fa07a to your computer and use it in GitHub Desktop.
Save jerrickhakim/b0b3bd279e7c996a567a03ddd94fa07a to your computer and use it in GitHub Desktop.
.htaccess 301 Redirect
Redirect 301 /landingurl https://newurl.com/
@jerrickhakim
Copy link
Author

This code you can place in your .htaccess file for 301 redirects. Here is an example. I have a single author blog site, and I don't want users to be taken to the author archive page when they click on my name in a blog post. I'd rather have the visitor be redirected to my blog page. You can also use this to create custom post category post pages with your page builders if you don't want to mess with editing template files.

However, the most common use case for this is when you change your permalink to a page or post. Having a 301 redirect will prevent visitors from seeing your 404 page. Below is an image of the code in my .htaccess file.
screen shot 2018-03-21 at 3 13 09 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment