Mobile app version of vmapp.org
Login or Join
Yeniel560

: Domain.com to www.domain.com .htaccess redirect working except one subdir I've setup a redirect in .htaccess to consolidate domain.com to www.domain.com traffic on our Apache server. Looks like this:

@Yeniel560

Posted in: #301Redirect #Apache #Htaccess #NoWww #Redirects

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

Looks like this:

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


Works as expected, except for the blog.

If I go to www.centerline.net/blog, I get the blog fine.
If I go to 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 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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Yeniel560

2 Comments

Sorted by latest first Latest Oldest Best

 

@Yeniel560

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), centerline.net/blog redirected to www.centerline.net/blog without issue.

10% popularity Vote Up Vote Down


 

@Hamaas447

Here's the relevant snippet from my .htaccess that works for me. I'm going in the opposite direction from you (from www.vyznev.net to 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/ -d
RewriteRule ^(.*[^/])$ vyznev.net// [NS,L,R=permanent]

#
# Canonicalize host name
#
RewriteCond %{HTTP_HOST} !^vyznev.net$
RewriteCond %{HTTP_HOST} ^(www.)?vyznev.net$ [NC]
RewriteRule ^(.*) vyznev.net/ [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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme