Skip to content

Instantly share code, notes, and snippets.

@kckrinke
Created February 28, 2019 17:17
Show Gist options
  • Save kckrinke/855ff054d8116ac0cfe4b551cda5cc4b to your computer and use it in GitHub Desktop.
Save kckrinke/855ff054d8116ac0cfe4b551cda5cc4b to your computer and use it in GitHub Desktop.
.htaccess tester
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^htaccess_tester.php.*
RewriteRule ^.*$ htaccess_tester.php [L]
</IfModule>
ErrorDocument 404 /htaccess_tester.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>htaccess tester</title>
</head>
<body>
<h1>Apache <tt>.htaccess</tt> tester.</h1>
<?php
if (isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == '404') {
echo "<p><tt>mod_rewrite</tt> is <em>not</em> working! You used the path <tt>" . $_SERVER['REQUEST_URI'] . "</tt> to request this page and yet a <em>404 - Not Found</em> status was received.</p>";
} elseif (strpos($_SERVER['REQUEST_URI'], 'htaccess_tester.php') === false) {
echo "<p><tt>mod_rewrite</tt> is working! You used the path <tt>" . $_SERVER['REQUEST_URI'] . "</tt> to request this page.</p>";
} elseif (is_readable(__DIR__.'/.htaccess') ) {
echo "<p><tt>mod_rewrite</tt> is <em>not</em> working! You used the path <tt>" . $_SERVER['REQUEST_URI'] . "</tt> to request this page.</p>";
echo "<p>The file .htaccess exists and is readable to the webserver. These are its contents: </p>\n<textarea style='width: 700px; height: 200px;'>";
echo file_get_contents(__DIR__.'/.htaccess');
echo "</textarea>";
} else {
echo "<p><strong>Error:</strong> The file .htaccess does not exist or it is not readable to the webserver. <br><br>Retieve a new version of the file here, and place it in your webroot. Make sure it is readable to the webserver.</p>";
die();
}
/* echo '<hr/>';
* echo "<h1>PHPinfo</h1>";
* echo "<p>Below you'll find the specifics of your PHP installation, for debugging purposes.</p>";
* phpinfo();*/
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment