top of page
Writer's pictureRobin Rozhon

Simple 301 Redirect Generator for htaccess in Google Spreadsheets

Use 301 redirects to protect hardly gained positions in search results and don’t let visitors find your certainly awesome 404 page. This straightforward 301 generator helps you manage simple redirect rules in one spreadsheet.


What is a redirect?

Redirection is forwarding website’s visitors and crawlers to a different URL than the one initially requested. It’s used when the URL of a page needs to be changed. More info can be also found in the official Google documentation.


Types of redirects (3xx)

  • 301 “Moved Permanently” – It means that the page (source) was moved permanently to a new location (URL).

  • 302 “Found” or Moved Temporarily” – It means that the page (source) was moved temporarily to a new location (URL).

  • 307 “Temporary Redirect” – There is a small difference between 302 and 307 (the 307 redirect only works with HTTP 1.1).


If you’re interested in a detailed description, you can read this list of HTTP status codes.


How can I redirect my website/page?

To include only the most common ones, I avoided listing all of them, but here’s a few:


  • .htaccess

  • Meta refresh

  • PHP

  • ASP

  • JavaScript


Note that the spreadsheet was built for redirects via .htaccess file, which can be found in the root folder of your site.


Redirect 301 vs. RedirectMatch 301

Both directives use Apache module mod_alias and the most important takeaway is that RedirectMatch allows using pattern matching (regular expressions). Redirect is only for a single URL (page or file).


RedirectMatch 301 ^/old-page/$ http://www.domain.com/new-page/

URL Query String Parameters

It starts to be a bit complicated once you need to redirect URL with a parameter because neither Redirect 301 nor RedirectMatch 301 would work.


  • URL with parameters: http://domain.com/?p=23

  • URL without parameters: http://domain.com/page23/

In order to be able to redirect http://domain.com/?p=23, you need to use mod_rewrite instead of mode_alias. See example:


RewriteEngine On
RewriteCond %{REQUEST_URI} ^/
RewriteCond %{QUERY_STRING} ^p=23$
RewriteRule ^(.*)$ http://www.domain.com/new-awesome-page/? [R=301,L]

* The sheet does not generate RewriteEngine On for a URL query string redirect, therefore, it has to be manually added above all mod_rewrite rules.


As you can see, it’s super easy to make a mistake and almost any mistake in .htaccess file has consequences (500 Internal Server Error) that make your site inaccessible. Therefore, I’ve created a spreadsheet that generates all redirect rules for me.


How to Use the Sheet

  1. Insert destination domain (cell D1)

  2. Insert a list of full URLs (including domain name) you want to redirect

  3. Specify a new page path for every URL that you want to redirect (full URL will be automatically generated as a combination of the destination domain and new page path)

  4. Copy redirection rules from column F to your .htaccess file


Remove Quotes

Important Note: If you try to redirect URL with parameters, the sheet automatically adds quotes before and after the redirection rule.


RewriteCond %{REQUEST_URI} ^/
RewriteCond %{QUERY_STRING} ^p=23$
RewriteRule ^(.*)$ http://www.domain.com/new-awesome-page/? [R=301,L]

These quotes must be removed. If you don’t delete them and add the rule to .htaccess file, the site will return 500 status code (Internal Server Error).


Redirect a subfolder to a page

Feel free to use regular expressions in your old URLs if you want to redirect multiple pages with a single rule.


Instead of inserting the following five URLs


http://domain.com/old/page1/
http://domain.com/old/page2/
http://domain.com/old/page3/
http://domain.com/old/page4/
http://domain.com/old/page5/

You can use only one line with the wildcard:


http://domain.com/old/(.*)

This will help you to redirect all pages from subfolder /old/ to a new page. However, as an SEO guy, it’s my duty to advise you to redirect each URL 1-to-1 because it’s a better solution for both visitors and search engines.


Validation

Sometimes, it may happen that you accidentally try to redirect a URL to the same URL, which would create a redirect loop. In order to prevent this situation, the sheet keeps an eye on that for you in the “Status” column.


I tend to be super organized so I like adding one more column with the date when the redirect rule was uploaded to the .htaccess file.


PRO TIP: Once all rules are saved in the .htaccess file, I like using Screaming Frog in the List mode to be sure that all redirect rules work as expected.


  • Check all destination URLs (use full URLs from the last column) whether they return 200 (success). There is no point of redirecting a URL to another URL that’s already being redirected (3xx) or doesn’t exist (4xx).

  • Check all old URLs whether they return 301.




Comments


bottom of page