0

So I have a number of pages with URLs end in the same thing but have different content between the main URL and the final suffix. Some of these have multiple levels. For example:

https://www.example.com/category-1/page-to-be-redirected

https://www.example.com/news/topic-1/page-to-be-redirected

https://www.example.com/subfolder/category-1/category-2/page-to-be-redirected

https://www.example.com/blog-news/page-to-be-redirected

I need a redirect rule which will find all of these instances (anything including '/page-to-be-redirected' in this example) and send them all back to the home page (e.g. https://www.example.com).

Any help / advice would be amazing. Thank you!!

2
  • In which product and operating system? Browser? IIS? Apache?
    – harrymc
    Commented Jun 18, 2019 at 10:28
  • It's a standard WordPress site, I'm looking for a redirect rule I can add to the .htaccess file as it's running on Apache.
    – Aimee
    Commented Jun 18, 2019 at 11:00

1 Answer 1

0

The simplest way to add and manage redirects in WordPress is by using the Redirection plugin. Install and activate the plugin. Once activated, visit Tools » Redirection to setup your redirects.

Documentation for the Redirection plugin can be found in this article.

If you would rather use the web server configuration file .htaccess, you will need to connect to your website using an FTP client. The .htaccess file resides in your WordPress site’s root directory. If you can’t see the file there, you need to set the FTP client to show hidden files. You may edit the .htaccess file in any text editor.

An example of a simple redirect (but much more can be found on the web) :

RewriteEngine On
Redirect 301 ^https://www.example.com/.*/page-to-be-redirected$ https://www.example.com/

For more information, see for example the article
Beginner’s Guide to Creating 301 Redirects in WordPress (Step by Step).

4
  • Thank you. I've used the Redirection plugin previously though, that's not what I need in this instance. I've also used the .htaccess file to add 301 redirects via FTP thousands of times previously. What I'm looking for is the redirect rule I'd need to solve the issue mentioned above. As mentioned, I have multiple versions of a URL and I need a way to catch them all and automatically redirect them back to the home page. I just can't find the rule I'm looking for that would work when there are (multiple) different levels prior to the section of the slug which reflects the page title.
    – Aimee
    Commented Jun 18, 2019 at 12:21
  • Apache mod_rewrite supports regular expressions. Is the problem just formulating the regex?
    – harrymc
    Commented Jun 18, 2019 at 12:26
  • Yeah, sorry... I'm not sure what it is exactly that I need to write when it comes to the actual regex I need to use. :/
    – Aimee
    Commented Jun 19, 2019 at 11:35
  • I tried my hand at writing the rule. See my answer.
    – harrymc
    Commented Jun 19, 2019 at 13:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .