WP-cpanel

WordPress, cPanel, Redirects and htaccess

Having trouble setting up redirects in your cPanel for your WordPress website?

cPanel is a great hosting control panel interface.  My favorite commercial option. And WordPress is a wonderful content management system (CMS), so much so that more websites are running on it than on any other CMS wordwide.

So lets say you just built a new website for yourself or a client, and you are hosting the new site on a host using cPanel.  Lets say that your old website was programmed in straight HTML or PHP or any other variety other than one that ends in the same fashion as your new WordPress site ends.  The result might be something like this for your About Us page:

Old site:  http://mysite.com/about-us.html

New site: http://mysite.com/about-us/

Now some people may have a bookmark to your old site, to that specific page.  And search engines have your about us page ranked at that old url.  But when someone goes to http://mysite.com/about-us.html they are going to get an error page – because that page does not exist.

In comes the redirect.

The redirect allows you to make it so that anyone going to http://mysite.com/about-us.html is automatically redirected to http://mysite.com/about-us/.  Great.  Problem solved.  And a permanent redirect (301) will tell search engines that this is the new location for that old website address.  Perfect.

So lets just go into our cPanel and create a redirect.  (If you know how to edit an .htaccess file, then of course you could go in and do that, but if you are reading this, you likely do not know how to format such a statement in your .htaccess file to tell it to do what you want – or you want the convenience of the cPanel interface to make it easier.)

So you create your redirect in the cPanel – and it does not work.  Ugh!

The Solution

Luckily there is a solution.

You do have to edit the .htaccess file, but nothing complex.  Lets take a look. Here is the code from a WP install .htaccess file:

RewriteOptions inherit
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^main.htm$ "http://mydomain.com/" [R=301,L]

Just take the part that wraps around the WordPress part, and move it to the end, after the newly added  Rewrite rule(s).  And it will look like this:

RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^main.htm$ "http://mydomain.com/" [R=301,L]

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

That is it. Well, if you don’t know how to edit your .htaccess file, I will leave that extra research up to you. In summary, first you need to have a way to see the file in your directory since it starts with a dot (.), and then edit it, likely in a plain text editor. And possibly you may be able to edit it from within cPanel’s FileManager, but I have not checked. Again, I will leave that up to you.

Good luck.

11 Responses to WordPress, cPanel, Redirects and htaccess

  1. Amanda Floeckner August 2, 2016 at 1:35 am #

    Was having redirect problems on a new site for a client and looked all over the place for a solution. I can’t believe this post is from 2012 and it still worked for me! Problem solved. Thank you for the post and providing such a clear explanation on how to make the changes.

  2. Peter January 7, 2015 at 11:34 am #

    Hi
    I placed a rewrite/redirect rule in my cpanel to redirect my blog http://www.wildflowersaromatherapy.com/blog/ to my website. I have searched through all the .htaccess files and can’t find the redirect culprit.
    Is there any way you know of to search all the cpanel files and folders for this lost redirect code.
    I can open up my http://www.wildflowersaromatherapy.com/blog/ but anything after the trailing / gets redirected. Hope you can help.
    Thanks
    Peter

    • David Tierney January 8, 2015 at 5:01 pm #

      Hi Peter,

      If you added that rule via your cpanel, I believe it would have been added to the .htaccess file in the root of your domain name directly at http://www.wildflowersaromatherapy.com. Do you look there and not find any such rule? And did you look in your cpanel and see if you can remove it in the same cpanel pane as you created it? Otherwise, you could contact your hosting provider and see if they can fix it for you. I am guessing from what you shared that your intent is to remove the rewrite rule you created?

  3. Pete Nikolai May 13, 2014 at 10:59 am #

    Thanks for providing the missing piece of the puzzle. As I was setting up some redirects using cPanel and documenting the process to help my blog’s readers, I thought I had done everything correctly but the redirects were not working. I had seen several posting talking about how to code a redirect on the htaccess file, but that seemed beyond my ability. Thankfully I found your post and the simple procedure for modifying the htaccess file to move the WordPress text after the Rewrite rules.

    I’ve provided the step-by-step checklist at http://www.petenikolai.com/page-redirect/ including how to use cPanel’s Redirects utility to create the redirects and how to use File Manager to find and edit htaccess.

    • David Tierney May 13, 2014 at 11:55 am #

      Always nice to see someone benefiting from blog posts.

  4. rinshad March 18, 2014 at 7:43 am #

    Hello David,

    I am doing this method for my client website and its working. But now my client planning to make more redirects and he will set up this with the cpanel. Each time he will add a redirect through cpanel it will fail and I need to move these redirect rule to above wordpress entries to work this. He need not want to contact me all the time to add these redirects. How he can add redirects through cpanel .

    Kind regards
    Rinshad

    • David Tierney March 18, 2014 at 2:41 pm #

      I am glad this helped you. Unfortunately the only way I could think of that he could do this via cPanel is for you to tell him how to edit the htaccess file via the filemanager. And perhaps to save a backup copy each time in case he makes an error in the htaccess file.

  5. Andrew Thompson March 8, 2013 at 8:59 am #

    Thanks very much. I searched for hours – I knew there was a workaround and as always its something obvious 🙂 Much appreciated

Trackbacks/Pingbacks

  1. How to Redirect Users to a Different URL | Hybrid Self-Publishing - May 13, 2014

    […] cut selected text and paste it at the bottom (below the Rewrite rules)–my thanks to David Tierney for this […]

Leave a Comment. Join the Conversation!
Did that help? Do you have questions?

Pin It on Pinterest

Share This

Share This

Share this post with your friends!