• I’ve installed WordPress MU and I am using sub-domains. Now if subdomain doesn’t exist it will redirect visitor to a page defined in wp-config.php like this:

    define( ‘NOBLOGREDIRECT’, ‘http://www.mydomain.com/404-error’ );

    Now on that page I have some script and I need to extract “originally requested URL”. E.g. if user wanted to visit: blogs.mydomain.com and that blog doesn’t exist – user will see http://www.mydomain.com/404-error and on that page – how can I detect which domain user requested ?

    I’ve tried $_SERVER[‘HTTP_REFERER’] but it’s always empty.

    Any ideas ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    I’ve tried $_SERVER[‘HTTP_REFERER’] but it’s always empty.

    Sure because it got redirected via WP to that page so the referrer is itself. Love that logic.

    I wonder if this workaound would be it: http://frumph.net/2010/06/05/wordpress-3-0-multisite-subdomain-installation-noblogredirect-behavior-fix/

    Thread Starter peterbra

    (@peterbra)

    No, it doesn’t work for me, so I’ve decide to go different way. This is my htaccess:

    RewriteCond %{HTTP_HOST} !^(www|ws)\. [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$
    RewriteRule ^(.*)$ http://www.MYDOMAIN.com/check.php$1?username=%1 [QSA,L,R=301]
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]

    Now, in check.php I have basics:

    $username = $_REQUEST["username"];
           if ( username_exists( $username ) )
               echo "In Use - load content";
           else
               echo "Not In Use... serve my predefined content";

    Now even if blog exist – I am not sure how to trick .htaccess to proceed with loading actual blog and if it doesn’t exist I would like to serve content in wordpress manner…
    e.g: blog.mydomain.com exist and user will see actual blog and test.mydomain.com doesn’t exist, but I would like visitor to be on test.mydomain.com and serve him some content. Is this possible ?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Not with no-blog-redirect. It’s literally redirecting. If you left the page alone it would go to example.com/wp-signup.php?new=test

    And then you could customize the signuppage.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress MU – get requested subdomain’ is closed to new replies.