Typically, redirecting the domain to a different address is not a problem, especially if we have CMS systems that allow the smooth addition of 301 redirects. Especially in WordPress, which have so many plugins allowing us to quickly modify and add redirections.
In an equally simple way, we can manage redirections of individual subpages, eg if we have optimized part of the URLs or removed outdated content from the website. Just upload the .csv file or set the redirection manually. We then have the certainty that it will work immediately and without a problem.
The issue looks different when the domain within which we set up redirections does not have a convenient CMS. Then we have to use the htaccess file. This is much more problematic, especially for a positioner who previously had no contact with this rather capricious file. This article is just for you. I have prepared a few rules that can facilitate this difficult task.
Redirecting a single URL in htaccess is not a big problem. We do it with the rule:
Redirect 301 /old-website https://domain.com.au/new-website
This way you should also redirect the entire domain, if you change not only the domain address but also URL addresses within the site (eg due to optimization activities). This complicates the whole process much, but that’s where the Excel and it formulas come for rescue. Paste the redirection matrix into the file, and in the third column enter the formula:
=CONCATENATE("Redirect 301 ";A1;" ";A2;)
With the help of the formula, we combine both columns! Just copy the last column and paste it into the htaccess file. Unfortunately, this is just the beginning of our struggle.
Enter the main domain address at the very end of the list. It is unintuitive, but thanks to this you will avoid problems with redirection of all of the following addresses. Remember that htaccess executes commands from the top rather than as a whole. Some rules at the beginning of the file may affect subsequent redirections.
Each time you set a new rule or redirect in htaccess, test it. It sounds obvious but in the case of htaccess it makes a lot of sense. Sometimes a situation may happen in which a single redirection begins to live its own life. You better discover them before the algorithm! Use tools for this if the site is large, or try out the URLs from the file randomly.
Of course, as a positioner, on Google you feel like a kid in a candy store. When setting redirections in htaccess you will be able to test your research performance. When finding solutions for problems with htaccess, you’ll find that there are a lot of them, but not every one of them will work on your redirections. Pay attention to the rules preceding redirections, as they may interfere with the indications below.
Prepare for unexpected problems with the htaccess file, because it can be unpredictable, especially for the person who associates it only with the exclusion of certain parts of the website from the watchful eye of the algorithm.
Unfortunately, redirections in htaccess do not cope with various wrong URLs containing unusual characters such as spaces or brackets. The result of attempts to route these types of addresses by the standard method can be generating addresses returning error 404. To avoid such problems, trace all occurrences of spaces in the document (they are encoded as% 20).
Try the following formula:
Redirect 301 “/old url with spaces” domain.com.au/new-url-without-spaces
Where each instance of the %20 combination URL is swapped for space. It is important to include the URL with spaces in quotation marks – this tells the redirection that it is to pay attention exactly to the address indicated. Instead of using spaces, you can also try the following combinations:
Redirect 301 “/old\ url\ with\ spaces” domain.com.au/new-url-without-spaces
Redirect 301 “/old\surl\swith\sspaces” domain.com.au/new-url-without-spaces
Redirect 301 “/old[\s]url[\s]with[\s]spaces” domain.com.au/new-url-without-spaces
We do the same when there are brackets in our addresses. Brackets are another sign with which traditional redirection can not handle. The idea is to reuse the trick from the previous subsection.
Redirect 301 “/old-url\(with-bracket\)”domain.com.au/new-url-without-bracket
Before every bracket, I inserted a backslash, indicating that this is part of the address and a full-fledged character, not a fragment of the formula. In this way, the changed URL should be redirected to the desired address without any problem.
Redirecting addresses in htaccess requires from us more knowledge and the ability to prepare the file. We must remember about such issues as the correct set of formulas and modify them appropriately, depending on the needs (eg in the case of brackets and spaces and special characters). This is not the simplest thing, and it can take us a surprisingly long time. As a result, however, we get well-functioning redirects that convey the traffic and value of the landing page.