WarpConduit Computing

  • Quick Tips
  • Web Design & Development
  • Graphic Design
  • Home
  • WordPress Plugins
  • Password Generator
  • About
  • Contact

Setup WordPress to Respond to Multiple Site URLs

July 23, 2011 by Josh Hartman

Have you ever encountered a case where you want to access your WordPress site from multiple site URLs (for example a local URL and an external URL, or multiple external URLs)?

Solution

Change the Site URL and Home URL to a relative URL, making the domain name irrelevant to loading the site. Oh, but it can’t be as simple as updating that on the Settings->General admin page, no…WordPress requires a valid URL. Well don’t give up, you’ll just have to hack the option directly in the database.

  1. Connect to your WordPress database using a web-based utility like phpMyAdmin or another SQL client such as HeidiSQL.
  2. Open your wp_options table for editing (if applicable, use your table prefix instead of wp_).
  3. Find the rows with an option_name of siteurl or home and change the option_value of each to / if WordPress is installed in the root of your website or /path/to/wordpress if your WordPress site is installed in a sub-directory. Do NOT add a trailing slash.
  4. For those wanting to execute a simple SQL query, here is an example:
    UPDATE wp_options SET option_value = '/' WHERE option_name IN('siteurl', 'home');

    UPDATE wp_options SET option_value = '/' WHERE option_name IN('siteurl', 'home');

  5. Test your site out by going to your site URLs (for example http://192.168.0.1, http://mywebserver.local, http://www.example.com).

Important Note: This method is a hack and therefore isn’t a behavior WordPress developers intended. I wouldn’t recommend it for a production site. I have noticed that after making this change on a site that the admin login page lacks CSS, the toolbar on the Visual Editor is missing, and the front-end admin bar sometimes fails to be styled and shows at the bottom on pages. I haven’t seen any issues with the normal front-end site that visitors see. So be aware of some admin CSS problems.

Hope that tip can help some of you out, I know it was useful to me.

Filed Under: Web Design & Development Tagged With: url, wordpress

Comments

  1. Jenny Repair says

    July 31, 2011 at 2:18 AM

    Just added you to definitely my favorite blogs. Keep these posts coming!

  2. Quinten says

    April 6, 2012 at 6:45 AM

    I also updated the dashboard_widget_options option as well. Not sure if this had any impact but I’m now running the admin section with no dramas from multiple URL’s.

    This query will help you find any references to you siteurl/home urls:

    SELECT *
    FROM `wp_options` 
    WHERE `option_value` LIKE '%http://192.168.1.1%'

    SELECT * FROM `wp_options` WHERE `option_value` LIKE '%http://192.168.1.1%'

    Replacing “http://192.168.1.1” with your current siteurl.

    The following query can be used to update any reference:

    UPDATE `wp_options`
    SET `option_value` = REPLACE(`option_value`, 'http://192.168.1.1/', '/')
    WHERE `option_value` LIKE '%http://192.168.1%'

    UPDATE `wp_options` SET `option_value` = REPLACE(`option_value`, 'http://192.168.1.1/', '/') WHERE `option_value` LIKE '%http://192.168.1%'

    NOTE: I’m going from http://192.168.1.1/wordpress/ to /wordpress/

  3. Stephen Cotton says

    June 29, 2012 at 1:29 PM

    Sooo, I stumbled upon the same solution as you did around the same time. We use subversion internally, so those links have to be cleared out to / whenever we start a new project. The one thing that was bugging me though was that when the site url is a /, a number of wordpress default scripts and styles become relative links instead of absolute links.
    So, for example, jquery. It should include /wp-includes/js/jquery/jquery.js, but instead it takes whatever url you are on and tacks on the /wp-includes/js…. This means that on a page like /contact-us, jquery was being search for at /contact-us/wp-includes/js…. While I typically replace jquery with the most recent version for the theme of the site, I still needed to find a solution for the other default scripts and stylesheets. Finally, I figured it out:

    add_action('wp_default_scripts','dev_js_fix');
    function dev_js_fix( &$scripts ){
    	if($js_script = $scripts->query('admin-bar')){
    		$js_script->src = 'http://'.$_SERVER['HTTP_HOST'].'https://d3qpxhs44jx97p.cloudfront.net/wp-includes/js/admin-bar.js';
    		$scripts->remove('admin-bar');
    		$scripts->add('admin-bar',$js_script->src, $js_script->deps, $js_script->ver);
    	}
    	if($js_script = $scripts->query('jquery')){
    		$js_script->src = 'http://'.$_SERVER['HTTP_HOST'].'https://d3qpxhs44jx97p.cloudfront.net/wp-includes/js/jquery/jquery.js';
    		$scripts->remove('jquery');
    		$scripts->add('jquery',$js_script->src, $js_script->deps, $js_script->ver);
    	}
    }
     
    add_action('wp_default_styles','dev_css_fix');
    function dev_css_fix( &$styles ){
    	if($css_file = $styles->query('admin-bar')){
    		$css_file->src = 'http://'.$_SERVER['HTTP_HOST'].'https://d3qpxhs44jx97p.cloudfront.net/wp-includes/css/admin-bar.css';
    		$styles->remove('admin-bar');
    		$styles->add('admin-bar',$css_file->src);
    	}
    }

    add_action('wp_default_scripts','dev_js_fix'); function dev_js_fix( &$scripts ){ if($js_script = $scripts->query('admin-bar')){ $js_script->src = 'http://'.$_SERVER['HTTP_HOST'].'https://d3qpxhs44jx97p.cloudfront.net/wp-includes/js/admin-bar.js'; $scripts->remove('admin-bar'); $scripts->add('admin-bar',$js_script->src, $js_script->deps, $js_script->ver); } if($js_script = $scripts->query('jquery')){ $js_script->src = 'http://'.$_SERVER['HTTP_HOST'].'https://d3qpxhs44jx97p.cloudfront.net/wp-includes/js/jquery/jquery.js'; $scripts->remove('jquery'); $scripts->add('jquery',$js_script->src, $js_script->deps, $js_script->ver); } } add_action('wp_default_styles','dev_css_fix'); function dev_css_fix( &$styles ){ if($css_file = $styles->query('admin-bar')){ $css_file->src = 'http://'.$_SERVER['HTTP_HOST'].'https://d3qpxhs44jx97p.cloudfront.net/wp-includes/css/admin-bar.css'; $styles->remove('admin-bar'); $styles->add('admin-bar',$css_file->src); } }

    I hope this helps someone out and saves them the headaches I have had over it!

    • Josh Hartman says

      July 12, 2012 at 11:51 AM

      I’ll have to try this out, thanks Stephen!

Connect

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • Extremely Useful Applications for Web Development and IT Tasks
  • Installing BookStack Wiki on cPanel Shared Hosting
  • Media (MIME) Type Reference List

Tags

automatic base64 benchmark cache counter css deflate email font gzip htaccess html image inarray increment inline images in_array javascript jquery link list magento mailto menu metadot mysql number obfuscation opencart operating system order php random redirect rewriterule slashes software timestamp ubuntu unix upgrade url windows windows 7 wordpress

Blogroll

  • CodeIgniter
  • Fusion Forward
  • jQuery
  • Nettuts+
  • Smashing Magazine

© 2021 WarpConduit Computing. All Rights Reserved.