wp plugin - force www. in url
This nifty little WordPress plugin will force the url to include the 'www.' part of the url string. Useful if you want your address to be displayed in a particular way regardless of how the user types it in. To see how it works delete the www. from your address bar (i.e. http://samburdge.co.uk) and press return. This type of redirection is usualy done by altering the .htaccess file, which some Wordpress users may not have access to. Using a plugin to do this is an easy solution for WordPress users as the setup process is simple, and will be familiar to most of you.
Instructions:
- Download the plugin file here: URL to Full URL Plugin (rar) | URL to Full URL Plugin (zip)
- Upload the php file into your plugins folder (/wp-content/plugins/)
- Go to your plugins page in WordPress and activate the plugin
here's an example of the code:
/* Plugin Name: URL to full URL Plugin URI: http://www.samburdge.co.uk Description: Adds www. to the URL Version: 1 Author: Sam Burdge Author URI: http://www.samburdge.co.uk*/ function url_to_full (){ // read the host from the server environment $host = $_SERVER["HTTP_HOST"]; $host = strtolower($host); $host = trim($host); $host = str_replace(':80', '', $host); $host = trim($host); $thesite = get_settings('siteurl'); $myarr = explode('://', $thesite); $final = explode('/', $myarr[1]); // if the host is not starting with www. redirect the // user to the same URL but with www if ($host != $final[0]){ // You an also change the "!=" to "==", if you want to force // the user to use the domain name without the www. // send status header, so that search engines or other services // detect that this is a permanent redirect and not a temporary header('HTTP/1.1 301 Moved Permanently'); // read the URL the user requested: $url = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : ''; // redirect the user to the new destination: header('Location: http://'. $final[0] . '' . $url); // stop the script execution here exit; } } add_action('init', 'url_to_full');
The plugin has been tested using various formats of permalink structure. If you notice any bugs or faults with the plugin, please leave a comment on this post, as this is the first release of the plugin.






This is backwards… you should want to take the www out, not put it in… www is old and antiquated…
Hi Mr Papa,
I also have a plugin for that. Different strokes for different folks…
S
This is useful for people that want a correctly formatted URL. Antiquated because people are lazy.