wp plugin - remove www. from url
A slight variation from my previous wordpress plugin 'Force www. in URL'.
This plugin removes the www. from the url regardless of what the user has typed or the link they have followed.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: Remove www. Plugin (rar) | Remove www. 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: Remove www. from url Plugin URI: http://www.samburdge.co.uk Description: Removes www. from the url Version: 1.0 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]); $no_dots= explode('.', $final[0]); // 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 with 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://'. $no_dots[1] . '.' . $no_dots[2] . '.' . $no_dots[3] . '' . $url); // stop the script execution here exit; } } add_action('init', 'url_to_full');






Do you know how to undo this plugin? After activating this plugin I can’t login to my wp-admin anymore. I have Wordpress 2.6.2. When I try to go to wp-admin or wp-login.php it redirects me to http://nl../wp-admin instead of http://mydomain/wp-admin
By deleting the remove-www.php file my wp-admin works again so problem solved