Forums

Preview draft not working with different Site Address URL (4 posts)

  1. Twansparant
    Member
    Posted 6 months ago #

    Hi there,

    Since this topic: http://wordpress.org/support/topic/wp-30-preview-and-save-draft-functions-not-working is closed for some reason, I will continue here since this problem is far from solved!

    Basically, the generated preview url for drafts uses the site address url and not the wordpress address url and is therefore not working and giving a 404 error page.

    My url setup:
    - WordPress is installed in a root subfolder called 'blog' on my main domain A.
    - I have a second domain name B that points to my main domain A.
    - In my General Settings 'WordPress Address (URL)' has the following value: http://www.domain-a.com/blog
    - In my General Settings 'Site Address (URL)' has the following value: http://www.domain-b.com
    - I use a .htaccess file in my root to rewrite the url like this:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/blog/.*$
    RewriteRule ^(.*)$ /blog/$1

    All of the above works perfectly! Except for one little thing; previewing draft posts...
    The generated url when clicking 'preview draft' is as follows:

    http://www.domain-b.com/?p=2187&preview=true
    which results in a 404 'page not found' error page.

    When I manually change the url address into:
    http://www.domain-a.com/blog/?p=2187&preview=true
    The draft preview shows up perfectly!

    I can't expect from all the users of my website to manually change this address all the time, so I was wundering if there is a solution for this any time soon?

    I read this article about manually rewriting the preview url:
    Rewrite wordpress preview URL using .htaccess
    but that's only useful if the generated preview url allready consists of the WordPress Address URL and not the Site Address URL.

    Does anyone have a fix or workaround for this annoying problem?
    Any help is appreciated!

    Cheers

  2. Twansparant
    Member
    Posted 6 months ago #

    So am I really the only person with this problem?
    I can't imagine I'm the only one using this setup with 2 domains?

  3. Twansparant
    Member
    Posted 6 months ago #

    I found this guide to rewrite the preview URL to a different (sub) domain, but I can't seem to get it working for my setup:
    How do you redirect URLs with a query string to another host?

    This is part of my .htaccess file in the root of domain-a:

    RewriteCond %{HTTP_HOST} =domain-b.com [NC]
    RewriteCond %{QUERY_STRING} ^(p=([0-9]+)&preview=true)
    RewriteRule ^$ domain-a.com/?%[0-9]+ [R=301,L]

    Any idea why this isn't working?
    Thanks!

  4. Twansparant
    Member
    Posted 6 months ago #

    Thanks to this post from Florian d'Erfurth I found a solution for this problem!

    Add these lines in your .htaccess file in the root of your wordpress installation folder (in this case in the folder 'blog'):

    RewriteCond %{HTTP_HOST} =domain-b.com [NC]
    RewriteCond %{QUERY_STRING} (preview=true)
    RewriteRule ^$ domain-a.com/blog/?%{QUERY_STRING} [R=301,L]

    And the generated draft preview url will be rewritten to the correct and working url!

Reply

You must log in to post.

About this Topic