: .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/
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
More posts by @Gail5422790
3 Comments
Sorted by latest first Latest Oldest Best
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
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.
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]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.