Skip to content

Commit 9cf3780

Browse files
committed
Added Apache rewrite control, allow dots in URLs, and PHP 8 timers.
1 parent b6c9078 commit 9cf3780

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.htaccess

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Enable rewriting engine
2+
RewriteEngine On
3+
4+
# Set the base for relative path substitution
5+
RewriteBase /
6+
7+
# Rewrite requests to index.php if the file or directory doesn't exist
8+
RewriteCond %{REQUEST_FILENAME} !-f
9+
RewriteCond %{REQUEST_FILENAME} !-d
10+
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
if ( empty( $_SERVER['SCRIPT_URI'] ) ) {
20+
// Discourage direct index file access.
21+
if ( '/index.php' === $_SERVER['REQUEST_URI'] ) {
2122
http_response_code( 503 );
2223
exit;
2324
}
@@ -60,7 +61,7 @@ function retry(): void {
6061
) or retry();
6162

6263
$request = preg_replace(
63-
'/[^a-z0-9_\/%\-]/',
64+
'/[^a-z0-9_\/%\-\.]+/',
6465
'',
6566
strtolower( substr_replace( $_SERVER['REQUEST_URI'], '', 0, strlen( dirname( $_SERVER['PHP_SELF'] ) ) ) )
6667
) ?: 'links';

links.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$timer = microtime( true );
3+
$timer = hrtime( true );
44

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

0 commit comments

Comments
 (0)