Skip to content

Commit

Permalink
Added Apache rewrite control, allow dots in URLs, and PHP 8 timers.
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Jul 31, 2023
1 parent b6c9078 commit 9cf3780
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Enable rewriting engine
RewriteEngine On

# Set the base for relative path substitution
RewriteBase /

# Rewrite requests to index.php if the file or directory doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
5 changes: 3 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

if ( empty( $_SERVER['SCRIPT_URI'] ) ) {
// Discourage direct index file access.
if ( '/index.php' === $_SERVER['REQUEST_URI'] ) {
http_response_code( 503 );
exit;
}
Expand Down Expand Up @@ -60,7 +61,7 @@ function retry(): void {
) or retry();

$request = preg_replace(
'/[^a-z0-9_\/%\-]/',
'/[^a-z0-9_\/%\-\.]+/',
'',
strtolower( substr_replace( $_SERVER['REQUEST_URI'], '', 0, strlen( dirname( $_SERVER['PHP_SELF'] ) ) ) )
) ?: 'links';
Expand Down
4 changes: 2 additions & 2 deletions links.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$timer = microtime( true );
$timer = hrtime( true );

header( 'Cache-Control: max-age=3600', true );
header( 'Pragma: public' );
Expand Down Expand Up @@ -256,7 +256,7 @@ function make_alt_link( array $basepoints, string $altendpoint, string $altfor,
'Powered by %s &bull; Generated in %s microseconds &bull; Generation ID: <code>%s</code>',
[
'<a href=https://theseoframework.com/>The SEO Framework</a>',
(int) abs( ( microtime( true ) - $timer ) * 1e6 ),
(int) abs( ( hrtime( true ) - $timer ) / 1e3 ),
bin2hex( random_bytes( 16 ) ),
]
);
Expand Down

0 comments on commit 9cf3780

Please sign in to comment.