Home>Support>/blog redirect loop

/blog redirect loop

My entire website uses wordpress and I have wordpress installed in folder /blog. I operate the site from the root level. Every aspect of my site works properly. However, one url: example.com/blog results in a redirect loop in all browsers. All files attached to /blog work properly. For example, example.com/blog/page1 loads just fine… but the category level /blog/ will not redirect to the homepage as it should. I wouldn’t have ever even noticed had I not found it indexed in Google. From an SEO perspective, I have no idea what type of damage an indexed page with a redirect loop could be harming my site. Any ideas? Also, I tried adding a redirect rule in htaccess but it just breaks the site (it won’t load).

Any ideas?

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    It sounds like an issue with the URL settings in WordPress.

    Can you please confirm that in the WordPress General settings your Website address(URL) is listed as:

    http://www.example.com

    And your WordPress address(URL) is listed as

    http://www.example.com/blog

    Let us know how you get on

    Magus

  2. 9 years, 5 months ago Chris Robbins

    Magus,

    Thank you for the reply. Yes, I have checked every setting I can think of and those are indeed the declarations in my General Settings. Would showing my htaccess and index.php in a separate reply be helpful? Also, I can’t find any conflicts with any of my plugins (for example, Yoast). Everything seems internally consistent.

  3. 9 years, 5 months ago Chris Robbins

    Magus,

    Also, I asked my hosting technical support about it and they kept pointing out that there are links to the /blog category in my homepage source code. To me it seems like normal behavior since my plugins are all in the /blog folder. For instance, they thought plugin references like this would cause the loop:

     <link rel='stylesheet' id='wpcci-admin-css-css'  href='http://www.example.com/blog/wp-content/plugins/wp-custom-css/css/wp-custom-css-admin-styles.css?ver=4.1.1' type='text/css' media='all' />  

    I don’t see how that would be part of the redirect loop, but tech support felt it was the problem.

  4. 9 years, 5 months ago Chris Robbins

    *correction to the last reply, they thought plugin AND stylesheet references to /blog could be causing the redirect loop. I think it’s a problem with my htaccess, but it all looks fine to me and the entire site is behaving as expected, minus the one url example.com/blog/

  5. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    You are correct, references like that, using the absolute path could never cause that problem. It may well be a problem in the .htaccess file. Could you please post that in a reply and I’ll have a look.

    Thanks

    Magus

  6. 9 years, 5 months ago Chris Robbins

    Magus,

    Below, I am including the htaccess and the index.php as they appear in the root and in /blog.

     
    htaccess in the root
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    
    ******************************
    index.php in the root
    
    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
    
    
    
    ******************************
    htaccess in the /blog folder
    
    #RewriteEngine On
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    
    
    
    
    ******************************
    Index.php in the /blog folder
    
    
    
    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    
    
  7. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    This is a problem with the .htaccess AND the index.php in the blog directory. Please change the .htaccess to read

    #RewriteEngine On
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    

    and change this line in the index.php

    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    

    to read

    require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
    

    Once done you should be set

    Let us know how you get on

    Magus

  8. 9 years, 5 months ago Chris Robbins

    Magus,

    Thank you so much. Do you think the htaccess/index.php files in the /blog directory are fine? You’re a genius in my opinion :) You’ve helped me so much this week and I appreciate both your willingness to help and your very polite/patient replies :)

  9. 9 years, 5 months ago Chris Robbins

    Magus,

    I am still getting a redirect loop. I’m wondering if the internal files need modifying (/blog htaccass and index.php)? I am also see index.php in other subfolders, like wp-content, wp-content/plugins, etc

  10. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    The changes I posted should have been put into the files in the blog subdirectory. The files in the root dir should have been left alone. The reason you were getting the redirect loop was because of the incorrect settings in the blog .htaccess.

    With webservers the ‘/’ symbol by itself means the site root folder. The htaccess in the blog folder was sending traffic to your site root, this was looking for an entry in wordpress for blog, which it could not find, so forwarded traffic back to the /blog/ folder. This in turn sent it back to the root and so on…..

    The only changes you need to make are the ones I posted before on the files in the blogs subdirectory

    Magus

  11. 9 years, 5 months ago Chris Robbins

    Magus,

    Thank you for clarifying. I restored my backups for the root files, and modified the /blog files as you suggested. I am getting error on line 17 (it’s now looking for a subfolder /blog/ inside /blog:

    Warning: require(/home/userID/public_html/blog/blog/wp-blog-header.php): failed to open stream: No such file or directory in /home/userID/public_html/blog/index.php on line 17

    Fatal error: require(): Failed opening required ‘/home/userID/public_html/blog/blog/wp-blog-header.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/userID/public_html/blog/index.php on line 17

  12. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    In that case, please try changing the line in index.php from your blog subdirectory back to it’s original setting and retest.

    Magus

  13. 9 years, 5 months ago Daniel
    Hi, I Work Here

    Hi Chris

    Did you have this solved?

    I see you have made a lot of progress in terms of changes. In order for me to troubleshoot where this issue might have come from, I request that you backup the whole site and do a fresh install of the theme. If the issue still arises let me know I pick it up from there.

    After this you could create a temporary admin account for us so we can log in and take a look? You can create the account with the following email address:

    [email protected]

    Just navigate to Users > Add New in your WordPress admin. Enter siteorigin for the username and [email protected] for the email address. Make sure you’ve selected Administrator for the role and enabled the “Send Password” field so we receive the details.

    Once we’re finished taking a look, you can delete this account. We’ll let you know when to do that.

    Looking forward to hearing from you

  14. 9 years, 5 months ago Chris Robbins

    Addo,

    Thank you for the reply, and I apologize for the delay in my response.

    I have to say I am so reluctant to do a complete reinstall only because of the amount of time I’ve spent on this over the past 10 days. Some of the methods that my hosting tech support tried resulted in downtime and they messed up my entire url structure (fortunately I had a backup). My fear is that the more I keep taking the site down and such, I will begin to see a negative impact on my SEO. So let me ask you, do you feel like there is a good chance that something within the wordpress core could be causing this and that a complete reinstall stands a decent chance of fixing it? What we’ve done so far:

    1) I’ve rebuilt index.php and htaccess for both /blog and root with the help of Magus and codex documentation.
    2) I’ve disabled all plugins to make sure there weren’t inappropriate specifications of canonical
    3) My webhost tested changing the general settings so that the website and blog urls match (using example.com/blog). This obviously eliminated the redirect loop, but it added /blog/ into my urls, which defeats the purpose of redirecting to root (I didn’t know they were going to do that as part of their fix and my site was up/live with those example.com/blog/file urls for about 4 hours before I caught it. I am surprised they weren’t working in a testing environment!
    4) I’ve ensured all hyperlinks in my site are in the correct form

    I discovered the example.com/blog/ redirect loop because I found the url indexed in Google. I went to my category listing in wp-admin and set /blog/ to noindex and excluded it from the sitemap.xml. I have also specified the canonical for example.com/blog/ to be example.com. These changes may be sufficient to at least get the url out of Google, and I can ignore the issue going forward. I have never used the /blog category, so what would happen if I delete it as a category? Would that conflict with the /blog directory folder? I was surprised to see that I have the option to “delete” showing on the /blog category page, but seeing it displayed is what led me to ask you about deleting it. Does /blog as a category have anything to do with /blog as a subdirectory of example.com? If not, could the existence of /blog as a category be causing the conflict?

    All other pages of the site work flawlessly. Never have html errors. The only redirect loop is example.com/blog/ (but example.com/blog/testpage resolves perfectly).

    If I have to rebuild, I will. I just wanted to inquire about how great the chance is that there is something corrupted or conflicting within my current installation. If I can delete /blog as a category without it messing up my directory /blog, I can certainly try that. I don’t see how they are related since my categories are stored in the database, not as a subdirectory of the root.

  15. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    You can safely remove blog as a category as it WILL be conflicting with blog as a subdirectory. This is due to the way that wordpress processes friendly URL’s.

    I believe we are still looking at a configuration error in one or both of the wordpress installations. Please check that they are set up as follows.

    MAIN SITE

    Site URL: http://www.example.com
    Wordpress URL: http://www.example.com

    .htaccess

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

    BLOG SITE

    Site URL: http://www.example.com

    WordPress URL: http://www.example.com/blog

    .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    

    The index.pho for both sites should read

    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    

    Let us know if this is how yours is configures

    Magus

  16. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    As a side thought, both of your WordPress installation would have had the database prefix set as wp_.

    Did you create a new database in your hosting package for the second installation or was it pointing to the same database as the primary site?

    If you ARE running them both through the same database then you will need to make sure they are both using different prefixes.

    You can find this setting in wp-config.php for each installation. The relevant line reads

    $table_prefix = 'wp_';
    

    You should keep this setting for your main site and alter the entry for your blog site to

    $table_prefix = 'wp_blog_';
    

    If they are running on different database instances then you can just ignore this post.

    Let us know if this helps
    Magus

  17. 9 years, 5 months ago Chris Robbins

    Magus,

    Thank you for your help. Can you clarify what you mean by “both installations of WordPress”? I am only one WordPress site, and I have WordPress installed in subdirectory /blog. I just want to make sure we’re on the same page and that I’m not misunderstanding something. Meanwhile, I will check the table_prefix right now.

  18. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    Maybe I misunderstood.
    Based on your Original Posts I thought your root site was running WordPress and you had a second installation of WordPress to act as your Blog installed in the /blog subdirectory?

    Magus

  19. 9 years, 5 months ago Chris Robbins

    Also… you said, “Did you create a new database in your hosting package for the second installation or was it pointing to the same database as the primary site?” I migrated servers within the same hosting company. My wordpress site was previously on a shared server, and I wanted a dedicated server. I think a new database was created because most of my php.ini settings were different after the migration. I had to go in and change a lot of things (like increase my media upload-size limit, memory, etc.).

  20. 9 years, 5 months ago Chris Robbins

    We replied at the same time :) I have a single installation, in a subdirectory named “blog”, but I am running the website from the root. My general settings in wp-admin are correct (regarding the blog/website urls). Also, my index.php and htaccess files are correct now that I’ve changed them based on the information you supplied in a previous comment above. Unfortunately, the redirect loop still occurs when trying to go from example.com/blog/ to example.com. I will check the table prefixes now, and I will also delete the /blog category since I’m not using it anyway.

  21. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    If you only have WordPress installed in the /blog subdirectory then I do not understand why you have wordpress files in your root and corresponding entries in the .htaccess file. Neither of these are actually needed when running WordPress from a subdirectory.

    Are you running another website from the root dir?

    Magus

  22. 9 years, 5 months ago Chris Robbins

    Magus

    I do not have wordpress files in the root. None at all. I have the htaccess file, which codex instructions tell me that I need. They specify to copy, not move, the wp-admin htaccess and index.php files to the root and make the required changes. Otherwise, no other wordpress files exist in the root. I simply have wordpress installed in /blog and the urls are redirected such that the blog appears to be running from the root.

  23. 9 years, 5 months ago Chris Robbins

    the entire site works fine. It works as expected. The only problem is that the single url: example.com/blog creates a redirect root. None of my other category urls do that. The only thing I can think of is a conflict between category=blog and subdirectory=blog

  24. 9 years, 5 months ago Chris Robbins

    CORRECTION:

    the entire site works fine. It works as expected. The only problem is that the single url: example.com/blog creates a redirect LOOP. None of my other category urls do that. The only thing I can think of is a conflict between category=blog and subdirectory=blog

  25. 9 years, 5 months ago Chris Robbins

    Magus,

    Are you saying that I do not need an htaccess or index.php file in the root in order to run my entire wordpress site from the root (installed in /blog)? At some point, we’ve gotten confused, and I want to make sure we’re on the same page.

  26. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    Now I have that clear please verify the following

    Root files:
    .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    

    index.php

    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
    

    /blog/ files
    .htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    

    index.php

    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
    

    Thanks
    Magus

  27. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    We are posting at the same time again :)

    Based on your setup your files SHOULD be as above.

    Because you have named your subdirectory ‘blog’ you cannot use that as a category or standalone page. If you want to use blog in this fashion you will need to change your subdirectory name and all the corresponding entries in the above files.

    Hope this clears it up

    Magus

  28. 9 years, 5 months ago Magus
    Hi, I Work Here

    sorry typo in the above, the bottom version of index.php should NOT have /blog in the front

    Magus

  29. 9 years, 5 months ago Chris Robbins

    Magus,

    Based on the information above (your last two posts, including your typo correction), the only difference is with my current root-level htaccess — which varies from what you have above.

    Mine is:

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

    In your comment above, both the root and /blog htacess are duplicates. Is that intended?

  30. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    Yes, based on the instructions in the codex for achieving what you want, you copy the .htaccess AFTER setting the WordPress address to http://www.example.com/blog. When you make this change in wordpress, it rewrites the .htaccess file to be as I have posted it so both copies should be identical.

    Magus

  31. 9 years, 5 months ago Chris Robbins

    oh I see. Maybe that’s part of my problem. Although the category=subdirectory name could be part of the problem also. I’ll try the htaccess changes first.

  32. 9 years, 5 months ago Chris Robbins

    Ok,

    Well I’ve change the root .htaccess so that it is identical to your instructions and matches the /blog .htaccess.
    Even after clearing cache, clearing browser cookies, etc., there was no change in the website behavior. I simply don’t understand it. If I had an incorrect root-level htaccess, then how was the website functioning at all? Making the modifications caused not even the slightest change in the website behavior and the infinite loop still occurs on example.com/blog

    Assuming my htaccess files are correct, I might try removing the category /blog.

  33. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    I don’t know if you missed this comment above

    ‘Because you have named your subdirectory ‘blog’ you cannot use that as a category or standalone page. If you want to use blog in this fashion you will need to change your subdirectory name and all the corresponding entries in the above files.’

    Because blog exists as a subdirectory you cannot use it as a category or page slug, you could just try changing the page slug so it does not read as ‘blog’, or you could use ‘Blog’ as Linux servers and WordPress are case sensitive.

    Hope this helps

    Magus

  34. 9 years, 5 months ago Chris Robbins

    Just a quick update…. I have resolved my problem. In case anyone else has a similar issue in the future, my experience and solution will be on record. I have searched for over a week on Google/Bing regarding naming conflicts and I can’t find anything. You’re more likely to find suggestions for naming your dog than you are to find anything about WordPress naming conflicts. That’s the unfortunate state of modern search, however.

    It was indeed a conflict between having the installation directory AND a blog category using the same name. I changed the name of the installation folder, and now everything is working as expected. There are no longer any redirect loops occurring with the /blog category url.

    Thank you for your help Magus. Your suggestion that the naming conflict may be the culprit led me to just change the name of the installation directory. The whole process took 5 minutes. I should’ve done that from the beginning, because I had that nagging suspicion given given that htaccess was involved.

  35. 9 years, 5 months ago Chris Robbins

    Just a quick update…. I have resolved my problem. In case anyone else has a similar issue in the future, my experience and solution will be on record. I have searched for over a week on Google/Bing regarding naming conflicts and I can’t find anything. You’re more likely to find suggestions for naming your dog than you are to find anything about WordPress naming conflicts. That’s the unfortunate state of modern search, however.

    It was indeed a conflict between having the installation directory AND a blog category using the same name. I changed the name of the installation folder, and now everything is working as expected. There are no longer any redirect loops occurring with the /blog category url.

    Thank you for your help Magus. Your suggestion that the naming conflict may be the culprit led me to just change the name of the installation directory. The whole process took 5 minutes. I should’ve done that from the beginning, because I had that nagging suspicion given that htaccess was involved.

  36. 9 years, 5 months ago Magus
    Hi, I Work Here

    Hi Chris

    It was a slog but I’m glad you got it sorted

    Feel free to open a new thread if you need any more help

    Magus

  37. 9 years, 5 months ago Daniel
    Hi, I Work Here

    Hi Chris

    Thank you for sharing what you did there :)

    @Magus much appreciated

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More