1

I am using a 301 redirect plugin: Quick Page/Post Redirect Plugin and my site's URL is http://example.com <-- notice no www. This works great for the following scenario:

User types: example.com/campaign

My redirect of /campaign/ => http://example.com/longer-campaign-page-slug works. Awesome. However, this next scenario does not work:

User types: www.example.com/campaign

WordPress either 404s or tries to redirect to the most closely-named post (this is default behavior of WordPress as far as I can tell). Example, user lands at http://example.com/campaign-from-last-month because it is similarly named.

I tried adding this to .htaccess but it did nothing:

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Keep in mind, regular requests to actual pages work. For example: http://www.example.com/super/awesome/slug/path will successfully land to http://example.com/super/awesome/slug/path.

The www record is a CNAME to the A record. Would having both of these be their own A record (to same IP) improve the situation? Or is there another solution I'm missing?

2

Figured it out. Put that before WordPress rewrite.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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