Skip to content

Instantly share code, notes, and snippets.

@PatelUtkarsh
Last active October 29, 2018 08:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatelUtkarsh/1d912162638fc87e1b0827734c412379 to your computer and use it in GitHub Desktop.
Save PatelUtkarsh/1d912162638fc87e1b0827734c412379 to your computer and use it in GitHub Desktop.
Valet share url fix for WordPress with https support
<?php
/**
* Add this block in wp-config.php file.
*
* Move any other `WP_HOME` or `WP_SITEURL` in else condition if present.
*/
if ( isset( $_SERVER['HTTP_X_ORIGINAL_HOST'] ) ) {
$is_ssl = isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] );
$actual_link = ( $is_ssl ? "https" : "http" ) . "://{$_SERVER[ 'HTTP_X_ORIGINAL_HOST' ]}";
define( 'WP_HOME', $actual_link );
define( 'WP_SITEURL', $actual_link );
if ( $is_ssl ) {
$_SERVER['HTTPS'] = 1;
}
}
@PatelUtkarsh
Copy link
Author

In order for valet secure and valet share to work together
do valet secure
Edit file at ~/.valet/Nginx/{your_site}
Comment out first block like below

#server {
#    listen 80;
#    server_name example.dev www.example.dev *.example.dev;
#    return 301 https://$host$request_uri;
#}

This will not force https but https will work instead of giving you 301 redirect loop.

Ref: laravel/valet#382 (comment)

@PatelUtkarsh
Copy link
Author

Above comment is not working anymore, Use valet unsecure && valet share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment