3

No matter what url somebody uses to access my site, I'd like it to redirect to www.MyUrl.com. Is this possible?

3 Answers 3

6

As far as i know there is no way to force the url to uppercase.

As for forcing the www. this can vary as to where you are hosting etc.

Here is one generic way of doing this using your .htaccess file.

# Forcing www. infront of domain
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
3
  • 3
    You don't even need to use .htaccess to do this. WordPress does it natively. Just update the general settings page to include the www in the site's url. Aug 31, 2010 at 16:22
  • @Matt Ellioot: @John P Bloch is right, modifying .htaccess for this is massive overkill and has the potential to be screwed up accidentally down the road. Much better to define WP_HOME and WP_SITEURL instead. Aug 31, 2010 at 21:55
  • While you can't assume he is running Apache, using .htaccess is much more efficient than doing it within wordpress. Oct 24, 2010 at 21:34
3

Hi @FigBug:

1.) You can easily force "www" in your domain because WordPress handles it all for you. You'll only need to set two defines in the /wp-config.php file is found in your website's root; this is the same file where your database userid and password is stored.

Add these two lines to your /wp-config.php file somewhere before the require_once(ABSPATH . 'wp-settings.php'); line:

define('WP_HOME',"http://www.myurl.com");
define('WP_SITEURL',WP_HOME);

2.) You cannot force domain capitalization. Domains are case-insensitive. Even if you try WordPress will lowercase it.

(So give it up, it ain't happening! :-)

1
  • Hi Mike, what about in cases where the folder is in a different directory? Would this botch it up. Cheers, Noel
    – Noel Tock
    Jun 10, 2011 at 20:37
1

There are lots of ways to force a redirect from a given URL to a preferred variant of that URL. Which one you use will depend upon how much control you have over your environment. Some include:

  • Use the WordPress control panel settings.
  • Use the Apache .htaccess URL rewriting capabilities.
  • Use the Apache Redirect permanent directive from the Apache configuration. (All webserver should have a similar mechanism.)

What you have to keep in mind is that domain names are NOT case-sensitive, and in this case the browser will control what gets displayed, not your server. More importantly, each redirection you force will (1) require additional work from your server, (2) increase the complexity of your configuration, and (3) delay your users from accessing your site. If your goal is to enhance your brand (MyUrl instead of myurl) you'd be better served by focusing on the design of your site.

There are two real reasons to implement site redirection to force a given domain:

  1. Reduce search engine confusion (everyone uses myurl.com instead of www.myurl.com or web.myurl.com or 12.34.56.78).
  2. Ensure that all users of a SSL-protected site use the same domain that is registered in the SSL certificate, mostly to prevent error messages and confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.