I have a wordpress instalation that is not redirecting urls not starting with www.
Example: http://example.com/dir/ doesn’t send to http://www.example.com/dir/ instead goes to http://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=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
You should not have to modify your
.htaccess
; actually I would not recommend it.Sounds like you simply have your values for WordPress address and Site address set correctly in your admin console in the Settings > General section:
General section and the WordPress address and Site address”>
Another option is to add the following 2 lines somewhere within your
/wp-config.php
file but beforerequire_once(ABSPATH . 'wp-settings.php');
(and be sure not to use a trailing slash):I prefer this approach because I like to keep my configuration options in code whenever possible since it is easier to maintain that way than configuration options stored in the database.
Hope this helps.
-Mike
P.S. Next time you have a WordPress question, consider asking over at StackOverflow’s sister site WordPress Answers? Lots of WordPress enthusiasts over the to help out.
I got the correct answer from webmasters.stackexchange.com. This works perfectly! Thanks Ruel for pointing me to webmasters.stackexchange.
More like a question for http://webmasters.stackexchange.com
Well anyway, if you are using cPanel, you can do a wildcard redirect from
Redirects
underDomains
category.But if not, try this:
Works perfectly. Put this at the top of
wp-config.php
file: