WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Twansparant
    Member
    Posted 2 years 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 2 years 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 2 years 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 2 years 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!

  5. TDawg
    Member
    Posted 2 years ago #

    This has been very helpful and works great for previewing drafts under these conditions, but previewing Published posts still yields the error message "You do not have permission to preview drafts." Any idea why this would work for drafts and not published articles, and how I might alter the rule to apply to both?

    Thanks!

  6. Twansparant
    Member
    Posted 2 years ago #

    I think because the published preview drafts have 2 more query vars in the url. Example:
    domain-b.com/?preview=true&preview_id=7471&preview_nonce=18aaf803e2

    Somehow the rewrite rule should ALWAYS be applied when there's a preview=true in the url, now it's only applied when it's just that one query var.

    I'm no mod_rewrite expert, but there should be some sort of wildcard after the QUERY_STRING line:
    RewriteCond %{QUERY_STRING} (preview=true^)

  7. Twansparant
    Member
    Posted 2 years ago #

    I tried these 2 lines, but the error still comes up on the published previews. The draft preview rewrite still works though...

    RewriteCond %{QUERY_STRING} (^|&)preview=true(&|$)
    RewriteCond %{QUERY_STRING} ^(.*)preview=true(.*)$
  8. JuliePgh
    Member
    Posted 1 year ago #

    Hi, I'm new to wordpress and have encountered a problem which is similar to yours, though only one domain is involved. I couldn't follow what you were saying about the .htaccess file/coding, but I think you can help me.

    Basically, my URL is http://www.juliekcohen.com
    I set up my blog in a subfolder http://www.juliecohen.com/blog
    When I go into General settings and make the Site URL point to http://www.juliekcohen.com, my preview mode for any posts no longer works, and instead simply takes me to http://www.juliekcohen.com

    Can you recommend how I can fix this?

    Thanks,
    Julie

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    As per the Forum Welcome, please post your own topic. Your problem - despite any similarity in symptoms - is likely to be completely different.

Topic Closed

This topic has been closed to new replies.

About this Topic