Welcome to WebmasterWorld Guest from 34.204.173.36

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Redirect loop on a wordpress category page - htaccess issue?

Redirect loop on a single category url

     
6:03 am on Apr 16, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 3, 2002
posts:2586
votes: 3


I am encountering a redirect loop on one of my wordpress category pages (top-level category only; its sub-category pages load just fine).

I run a wordpress site on Apache.
I have wordpress installed in a subdirectory named "blog"
I use htaccess and index.php to access my website from the root
In other words, www.example.com accesses my wordpress site
I have no problems, whatsoever, with any of my urls; everything works perfectly, except ONE url
I wouldn't worry about it, but Google has the problem url indexed, and clicking on it = redirect loop (all browsers)
The problem url is: www.example.com/blog (with or without trailing slash after 'blog')
Sub-category pages of "blog" load with no problems
Category /blog/ could either redirect to the homepage -or- it could exist as a noindexed top-level category page
I just don't understand why it's the only top-level category url that is generating a redirect loop
All other top-level category pages load properly


Questions: Could it be that the category "blog" is competing with the subdirectory that it is installed in (also called "blog")? Should I rename the subdirectory? Or, should I rename the category/slug? I never even created a category named "blog", because I've always wanted my categories to be named according to the topic. I assume it is there as part of my theme, and I never realized that it would cause problems (if it is indeed the problem). It's all so strange.

My htaccess/index.php: The following are my rules for htaccess (in the root and in the subdirectory). It's clear that the category /blog/ is trying to redirect to the homepage, but it shouldn't be generating a redirect loop. Furthermore, it's indexed in Google without the "www" (www is canonical for my site).


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 subdirectory

# 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 subdirectory

<?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' );


I think everything is set up just fine. I am seeking any experts out there who may understand why the redirect loop is occurring on the one url example.com/blog

Again, is there a conflict between having this (unintended) blog category named "blog" and also the subdirectory in which wordpress is installed named "blog"? Maybe htaccess is trying to redirect both because they are both named the same thing?

Sorry for such a long post, but I hope someone out there is patient enough to read through it and can help me with this problem.

Thanks!
7:33 am on Apr 16, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4567
votes: 367


Your WP htaccess file should only be in the root directory. The settings in WP tell it where it really is. There should be only one index.php file. Sorry it is too late for me and my brain has stopped working, but I have the same setup, with my WP on one domain installed in a subdirectory. It may be causing a conflict to have it redirecting twice when the URL is the same both from the root and from the /blog/ subdirectory (it would be redirecting from /blog/ to the root directory where it gets another redirect to /blog/).
9:15 am on Apr 16, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 3, 2002
posts:2586
votes: 3


Your WP htaccess file should only be in the root directory. The settings in WP tell it where it really is. There should be only one index.php file.


The Wordpress Codex instructions say, "Copy (NOT MOVE!)" both the htaccess and index.php files from the WordPress installation directory to the root directory, and that's how I've done it. Maybe it's a typo, but they are very explicit. See item #7 here: [codex.wordpress.org ]

On another note, I have resolved my problem. 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.

I did want to share that success in case anyone else has a similar issue in the future, my experience will be on record. I have searched for over a week on Google/Bing regarding naming conflicts and I can't find anything. I'm more likely to find tips for naming your dog than I am anything related to wordpress. That's the unfortunate state of modern search, however.

So long story short, problem solved. Never name your installation folder "blog" if you are going to have a category named "blog" and expect it to work properly from the root.
6:21 pm on Apr 16, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15943
votes: 890


Or, more generically: Never give any real, physical directory the same name as an URL element used by your CMS.