Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Ok, so I have a wordpress site with a lot of pages and menus that I've defined in the appearance/menus section of wordpress.

One of my pages has a little payment form on, which I'd like to link to with https://blahlbah.com/thepage.. and for all the other pages I'd like them to remain as http.

Even if I set an absolute link to the https page all the other pages being relative links become https also after you visit that page.

Is there a plugin or a hack or something to just specify that one page as https?

Cheers, John.

share|improve this question
add comment

3 Answers

You will need to convert the relative links to absolute links. You can do this in the wp_nav_menu_objects filter, which gets all menu items. Just edit the url property of each item.

Another option would be to extend the default Walker_Nav_Menu with one that overrides start_el(), so you can modify the passed $item there before you pass it to the parent start_el().

These are relative links you added yourself? If you add a link to a WordPress Page or Post via the menu editor it should be absolute by default.

share|improve this answer
add comment

Here is some code to force SSL on non-ssl pages:

// Force SSL
if( !is_ssl() ){
    if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
    wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
    exit();
} else {
    wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit();
}

Basically, you can use this code to force ssl on your desired page(s) and do the opposite to remove ssl for all other pages. You may, in this case, want to specify the second parameter for wp_redirect to enable a 301 redirect rather than a 302. You will also want to ensure as best you can that all links point to the https version.

share|improve this answer
add comment

I like Jan's first idea--filtering wp_nav_menu_options. Could be a good all-around solution, and could be quickly turned into a plugin. Maybe even add a checkbox to the edit screen saying "serve this page over SSL" or something?

In the past, I've used a hacky redirect solution with htaccess. It looks something like:

# Force a given page to https
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /your-ssl-page/$
RewriteRule ^(.*)$ https://www.example.com/your-ssl-page/ [R=301,L]

# Force everything BUT the given page to regular http
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/your-ssl-page/$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

This works well (and is very easy to implement) if you're only worried about one page, but gets to be a real pain if you have a bunch of HTTPS URIs, or if you're not good at troubleshooting rewrite rules :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.