WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic wordpress base URL for hostname (3 posts)

  1. kingfunkmaster
    Member
    Posted 7 years ago #

    Hi all,

    This question came about as a precursor to another question I have about silently switching themes based on hostname.

    I have a site configured to respond on a number of subdomains using the same wordpress installation, but I'd like to have all the links work relative to whatever the entry address is, rather than the original base url.

    If anyone has ideas how this can be achieved I'd appreciate it.

    Cheers.
    Matt

  2. pla
    Member
    Posted 7 years ago #

    hi,

    i have the same problem.
    something that kind of works, is to modify the mysql options entry for "home" directory, when you use "/" all links are relative.
    but i got a problem with the admin area, some submissions lead to a 404 that way.

    what i'm trying now is writing a plugin hook to change the rendered absolute path based on my real server url.

    if you had any success please let me know.

    cheers, marc

  3. pla
    Member
    Posted 7 years ago #

    i found a solution:

    if you want to be able to run wordpress with different dynamic urls (aliases) linking to the same wordpress homedir, you can create a plugin with this function:

    function ml_clean_siteurl($url) {
    	$url="http://".$_SERVER[HTTP_HOST];
    	return $url;
    }
    add_filter('option_siteurl', 'ml_clean_siteurl');

    it tells wordpress to override the "siteurl" setting for internal links with the real server url.

    however, you should only do that if you're using additional plugins to seperate content for each alias (e.g. different languages on different subdomains), otherwise google will see duplicate content (bad for ranking).

Topic Closed

This topic has been closed to new replies.

About this Topic