0

I've setup a redirect in .htaccess to consolidate example.com to www.example.com traffic on our Apache server.

Looks like this:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^centerline\.net$ [NC]
RewriteRule ^(.*)$ http://www.centerline.net/$1 [R=301,L]

Works as expected, except for the blog.

If I go to http://www.centerline.net/blog, I get the blog fine. If I go to http://centerline.net/blog, it redirects to the home page (which is the 404 default action).

I tried commenting out the two lines to consolidate centerline.net to www.centerline.net, and I still can't get to the blog via centerline.net/blog.

There's nothing else in the .htaccess related to the blog URL. For the blog, there are several lines that Wordpress inserted into the .htaccess, but commenting those out makes no difference. Just in case, that code 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

Any ideas where else to look? Or something I'm missing?

3
  • 2
    Redirecting to the home page is not really a good 404 action. It confuses users and doesn't give them a chance to tell you what's broken. Commented Jan 18, 2012 at 17:20
  • Total agree. That wasn't my call. But that isn't the issue.
    – Keefer
    Commented Jan 18, 2012 at 17:43
  • I've renamed the .htaccess file temporarily and I still get the same behavior from /blog/ So I've ruled out that it's the root dir's .htaccess causing the problem. Where else should I look?
    – Keefer
    Commented Jan 18, 2012 at 21:14

2 Answers 2

1

Here's the relevant snippet from my .htaccess that works for me. I'm going in the opposite direction from you (from http://www.vyznev.net to http://vyznev.net), but the principle should be the same:

#
# URL rewrite engine setup
#
RewriteEngine On
RewriteBase /

#
# Append directory slash (because Apache seems to prepend "www.")
#
RewriteCond /www/asiakkaat/vyznev/public_html/$1 -d
RewriteRule ^(.*[^/])$ http://vyznev.net/$1/ [NS,L,R=permanent]

#
# Canonicalize host name
#
RewriteCond %{HTTP_HOST} !^vyznev\.net$
RewriteCond %{HTTP_HOST}  ^(www\.)?vyznev\.net$ [NC]
RewriteRule ^(.*) http://vyznev.net/$1 [NS,L,R=permanent]

The first RewriteRule is there just to avoid double redirects for directory URLs without a trailing slash; you probably won't need it, but I included it just in case.

To be honest, I have no idea why the code in your question shouldn't work just as well as mine does. But, in the absence of a better answer, I figured having a known working example might be of at least some help.

1

Found the issue. The root file had a .htaccess file. Everything in there was fine.

The /blog/ subdirectory though also had an .htaccess file with some duplicate rules. As soon as I renamed that .htaccess file (for all intents and purposes deleted it), http://centerline.net/blog redirected to http://www.centerline.net/blog without issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.