Created
July 21, 2011 13:35
-
-
Save KrofDrakula/1097186 to your computer and use it in GitHub Desktop.
Hash redirect
This file contains 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 | |
# Rewrite only if request does not map to a physical file | |
RewriteCond %{REQUEST_FILENAME} !-f | |
# Reroute all requests to our index.php file | |
RewriteRule ^(.*)$ index.php [QSA,L] |
This file contains 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 | |
// the base path for out redirect base | |
// use '/' to specify root redirect or `/subdir` for | |
// some specific path where the .htaccess resides | |
$basePath = '/somePath'; | |
/* | |
* This `if` condition checks for any path that follows | |
* the `$basePath` set above and redirects the browser | |
* from `$basePath/[...]` to `$basePath#[...]` | |
*/ | |
if(preg_match('@^' . $basePath . '/(.+)$@', $_SERVER['REQUEST_URI'], $matches)) { | |
echo <<<EOF | |
<script> | |
setTimeout(function() { | |
window.location="{$matches[1]}/mobile2#{$matches[2]}"; | |
}, 1000); | |
</script> | |
EOF; | |
exit; | |
} | |
// NOTE: we set a timeout to the script to slow down infinite redirect loops | |
// if something goes wrong. Use a lower value if you want. | |
// after this, output any HTML | |
?><!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Hello world!</h1> | |
<p> | |
<script> | |
document.write(window.location.hash); | |
</script> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment