2

The following is my current .htaccess file. If I open https://example.com/test and it doesn't end with one of the endings specified in line 2, it will open https://example.com/index.php?url=test

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(css|js|png|jpg|php|svg|gif|webm|webp|eot|ttf|woff|woff2)
RewriteRule ^([^/]+)/? index.php?url=$1 [L,QSA]

However, if I try to open https://example.com/something/test, it just opens ?url=something instead of ?url=something/test. How can I achieve this? I have absolutely no knowledge about regex stuff

DocRoot
  • 297
  • 1
  • 10
OfficialCRUGG
  • 55
  • 1
  • 4

1 Answers1

1

The regex ^([^/]+)/? only captures the first path segment, ie. [^/]+ matches 1 or more non-slash characters. If you wish to match the entire URL-path then use (.+) (to match 1 or more any characters). However, you can be more restrictive if you only want to match say 1 or 2 path segments?

and it doesn't end with one of the endings specified in line 2

That condition doesn't specifically check that the URL "ends" with one of those extensions, it checks that one of those extensions are contained within the filesystem path that the URL maps to. You need an end-of-string anchor $ at the end of the regex. And to specifically check the URL, you should check against the REQUEST_URI server variable.

So, this becomes:

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|php|svg|gif|webm|webp|eot|ttf|woff|woff2)$
RewriteRule (.+) index.php?url=$1 [L,QSA]
DocRoot
  • 297
  • 1
  • 10