Last active
February 8, 2016 14:20
-
-
Save lenivene/d0a5eef9fd12590ac825 to your computer and use it in GitHub Desktop.
Force loading with the WWW ( htaccess, php, nginx and web.config )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine On | |
RewriteCond %{HTTP_HOST} !^$ | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteCond %{HTTPS}s ^on(s)| | |
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_current_url(){ | |
$url = 'http'; | |
if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on'){ | |
$url .= s; | |
} | |
$url .= '://www.'; | |
if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] != 80 ) { | |
$url .= $_SERVER['SERVER_NAME'] . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; | |
}else{ | |
$url .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; | |
} | |
/* | |
* Is not required | |
*/ | |
//$url = str_replace( "'", '', $url ); | |
//$url = str_replace( '"', '', $url ); | |
return $url; | |
} | |
if ( strpos( $_SERVER['SERVER_NAME'], 'www.') === false ){ | |
@header( "Location: ". get_current_url(), true, 301 ); | |
exit(); | |
} | |
echo "Hello Word"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location / { | |
if ($http_host !~ "^$"){ | |
rewrite ^(.*)$ http%1://www.$http_host$request_uri redirect; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<rule name="rule 1f" stopProcessing="true"> | |
<match url="^" /> | |
<action type="Rewrite" url="/http%1://www.%{HTTP_HOST}%{REQUEST_URI}" /> | |
</rule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment