Forum Moderators: phranque

Message Too Old, No Replies

Need help with my .httaccess

         

noblesavage

5:58 am on Dec 22, 2006 (gmt 0)

10+ Year Member



I'm using Wordpress and I'm trying to 301 redirect all www. pages to non-www.

This is what I have so far:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Redirect to canonical domain
RewriteCond %{HTTP_HOST} ^www\.example.com [NC]
RewriteRule (.*) http://example.com$1 [R=301,L]
# WP premlinks
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

It works, but if I request a directory from www. it removes the "/"

If I request www.example.com/directory I get www.example.comdirectory

Thanks for any help

SteveWh

12:27 pm on Dec 22, 2006 (gmt 0)

10+ Year Member



This line:

RewriteCond %{HTTP_HOST} ^www\.example.com [NC]

should be

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]

However, this will work just as well (it means "starts with www."):

RewriteCond %{HTTP_HOST} ^www\. [NC]

This line:

RewriteRule (.*) http://example.com$1 [R=301,L]

should be

RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Sorry I don't know enough to comment on the remaining block:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]