skip to Main Content

Example:

websitename.com/page1 goes to websitename.com/awesome/page1
websitename.com/page2 goes to websitename.com/awesome/page2
websitename.com/page3 goes to websitename.com/awesome/page3

I can’t seem to find any solution to this, and I am very new to this world. Thanks

2

Answers


  1. There are many plugins that will do this, Redirection being one of the most popular.

    Redirection is the most popular redirect manager for WordPress. With it you can easily manage 301 redirections, keep track of 404 errors, and generally tidy up any loose ends your site may have. This can help reduce errors and improve your site ranking.

    Login or Signup to reply.
  2. If you prefer not to use a plugin, you can include this rule in the .htaccess file:

    RewriteRule ^page([0-9]+)/?$ /awesome/page$1 [R=301,L]
    

    For example:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^page([0-9]+)/?$ /awesome/page$1 [R=301,L]
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    Or you can use this code:

    add_action('init',function (){
        if(preg_match('#^/page(d+)$#',$_SERVER['REQUEST_URI'], $matches)){
            wp_redirect('/awesome/page' . $matches[1],301);
            exit;
        }
    },0);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search