简体   繁体   中英

URL Canonicalization for WordPress site

I have the website drwagenberg.com which can open on both URLs:

http://www.drwagenberg.com/
http://drwagenberg.com/

I want to canonicalize the URL http://drwagenberg.com/ , so that whenever the user types this URL it automatically makes it http://www.drwagenberg.com/

Keep in mind that the website is built in WordPress.

I've tried different methods like redirection in my .htacess file. Here is the code I used:

Redirect 301 / http://www.drwagenberg.com/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^drwagenberg\.com$ [NC]
RewriteRule ^(.*)$ http://www.drwagenberg.com/$1 [L,R=301]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>    
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

Try this. And get rid of the top line

Redirect 301 / http://www.drwagenberg.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM