Forum Moderators: phranque
I am very new to htaccess and need some help. basically what I am trying to do is alleviate any chance of google crawling my site with http://example.com/blog/articles-go-here
I just set up a blog located at http://www.example.com/blog/
I want to ensure that google never see's my site without "www." for cannonical issues that could become a headache down the road.
I am currently using the following snippet to keep my root directory pages pointing to the right place:
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST}!^www\.example.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [L,R=301]
It seems for each directory you have on your site, it needs a seperate .hta file in it. What code would be needed to make this work in the blog directory?
I am open for any suggestions if there is a better way to do this.
It redirects everything properly except everything in the blog directory.
----
edit:
Just went and tested a new directory. It works. SO it most def. must be a WordPress issue.
Now that I think about it. I am using the fuction of WordPress to mod rewrite the names of pages to be functional names instead of?id=12. So there is a htaccess file in the blog directory. Here is the code for it:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I am guessing the file in the blog directory is overwriting the file in the root directory.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /blog/index.php [L]
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST}!^www\.example.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [L,R=301]
</IfModule>
# END WordPress
which incidentally did not work. Any other ideas?
Thanks for the comments Jim.
This should be closer:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /blog/
#
# Redirect to canonical domain
RewriteCond %{HTTP_HOST} !^www\.example.com [NC]
RewriteRule ^(.*) http://www.example.com/blog/$1 [R=301,L]
#
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
# END WordPress
</IfModule>
Jim