Mobile app version of vmapp.org
Login or Join
Gail5422790

: .htaccess permanent redirect to www I have a WordPress installation that is not redirecting URLs not starting with www. Example: http://example.com/dir/ doesn't send to http://www.example.com/dir/

@Gail5422790

Posted in: #Htaccess #Redirects #Wordpress

I have a WordPress installation that is not redirecting URLs not starting with
Example: example.com/dir/ doesn't send to www.example.com/dir/ instead goes to example.com/.
How do I change the .htaccess below to always redirect to the page either using www or not?

# BEGIN WordPress
RewriteEngine On

RewriteBase /
RewriteRule ^index.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file= [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ [L]
RewriteRule . index.php [L]

# END WordPress

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Gail5422790

3 Comments

Sorted by latest first Latest Oldest Best

 

@Steve110

I would mix the two answers above


you HAVE to set properly the website URL So that the CMS always prints the correct address
you can set a proper rewrite rule so that in case someone links the wrong URL (no-www) you don't end up with Google indexing all pages twice penalizing the SEO ranking

10% popularity Vote Up Vote Down


 

@Looi9037786

Altering the .htaccess shouldn't be necessary. You should only need to change the website URL under Settings -> General in the WP Admin to include the
If you try John's answer and you have the website URL in WP settings set to the non-www version, you will create a redirect loop.

10% popularity Vote Up Vote Down


 

@Pope3001725

This snippet will force the www to always be in thew URL. I don't know if that helps you or not:

Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^(www.|$) [NC]
RewriteRule ^ www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme