From 97620cb583017c29a9418c13a070889dffc6758a Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 18:36:02 +0100 Subject: [PATCH 01/10] Add htaccess to redirect if not found to index If file not fount or directory not found redirect to index.html --- .htaccess | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .htaccess diff --git a/.htaccess b/.htaccess new file mode 100644 index 00000000..638a7c82 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^.*$ /index.html [L] From aec3de18aac433f37c4f91ef33397ae6b6eb34e1 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 18:51:32 +0100 Subject: [PATCH 02/10] Deleted .htaccess at wrong directory Sorry fucked it up, will correct it. --- .htaccess | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .htaccess diff --git a/.htaccess b/.htaccess deleted file mode 100644 index 638a7c82..00000000 --- a/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ -RewriteEngine on -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^.*$ /index.html [L] From cefd6ec752e4b908d0e7ddbac9de4c872f18a300 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 18:51:38 +0100 Subject: [PATCH 03/10] Add htaccess to redirect if not found to index If (file not found or directory not found) then > redirect to index.html --- public/.htaccess | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 public/.htaccess diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 00000000..638a7c82 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^.*$ /index.html [L] From 72e71aff401b7fd163f6571a8e94d798a6ee8e11 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 19:06:50 +0100 Subject: [PATCH 04/10] Updated htaccess to meet required functions. If a file gets called it will be redirected to index.html But not if it the requested File does contain a dot (and with this does have a file extension. If you call: links.domain.de/notexistingfile.jpg It will trigger 404 If you call: links.domain.de/server/[CODE-CODE-CODE]/list-short-urls/1 It will redirect the call to index.html --- public/.htaccess | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/.htaccess b/public/.htaccess index 638a7c82..5f7ad3a8 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,4 +1,3 @@ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^.*$ /index.html [L] +RewriteRule /[^/.]+$ /index.html [L] From 2ef330c62bfbc5527c6b47eafa6970e6fa1fa31d Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 20:49:46 +0100 Subject: [PATCH 05/10] Updated htaccess --- public/.htaccess | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public/.htaccess b/public/.htaccess index 5f7ad3a8..a04ff98c 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,3 +1,14 @@ RewriteEngine on +RewriteBase / + +# do not do anything for already existing files +RewriteCond %{REQUEST_FILENAME} -f [OR] +RewriteCond %{REQUEST_FILENAME} -l [OR] +RewriteCond %{REQUEST_FILENAME} -d +RewriteRule .+ - [L] + RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule /[^/.]+$ /index.html [L] +RewriteCond %{REQUEST_FILENAME} !-d +# if static asset do not do anything +RewriteRule (.*)(css|js|html|png|jpg|jpeg|json|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [L] +RewriteRule (.*) /index.html [L] From ab6dff5c3173bae93b63f7f3c7b0112a73cae393 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 20:51:23 +0100 Subject: [PATCH 06/10] Updates htaccess return 404 error if static assets does not exist --- public/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/.htaccess b/public/.htaccess index a04ff98c..d135ef6c 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -10,5 +10,5 @@ RewriteRule .+ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # if static asset do not do anything -RewriteRule (.*)(css|js|html|png|jpg|jpeg|json|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [L] +RewriteRule (.*)(css|js|html|png|jpg|json|jpeg|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [L,R=404] RewriteRule (.*) /index.html [L] From 703addddb9fccc3ecbef9d320a115681c85ffb27 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Thu, 30 Jan 2020 21:05:20 +0100 Subject: [PATCH 07/10] updated htaccess deleted second json (just needed once) --- public/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/.htaccess b/public/.htaccess index d135ef6c..aff8e51d 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -10,5 +10,5 @@ RewriteRule .+ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # if static asset do not do anything -RewriteRule (.*)(css|js|html|png|jpg|json|jpeg|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [L,R=404] +RewriteRule (.*)(css|js|html|png|jpg|jpeg|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [L,R=404] RewriteRule (.*) /index.html [L] From 965c2b243f94c97e67a75ca1d2f1695203fc58c2 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Fri, 31 Jan 2020 01:27:13 +0100 Subject: [PATCH 08/10] Update .htaccess 1. added more comments. 2. added NC Tag for making all the static assets case insensetive ("jpg" now matches "jpg" and "JPG" and so on) 3. transformed "jpe|jpeg" into "jpe?g" as its regex for the same, but shorter 4. changed line 8 from "+" to "*" to match everything, also zero times the wildcard --- public/.htaccess | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/.htaccess b/public/.htaccess index aff8e51d..d554246d 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -5,10 +5,12 @@ RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d -RewriteRule .+ - [L] +RewriteRule .* - [L] +# if request is no valid file NOR directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # if static asset do not do anything -RewriteRule (.*)(css|js|html|png|jpg|jpeg|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [L,R=404] +RewriteRule (.*)(css|js|html|png|jpe?g|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [NC,L,R=404] +# everything else should be redirected to /index.html so it can be routed by it RewriteRule (.*) /index.html [L] From c16f760d79d09ec53cf04e1dcf407e4d1a48d5e8 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Fri, 31 Jan 2020 01:29:41 +0100 Subject: [PATCH 09/10] Update .htaccess 1. removed $ (dollar sign from line 14 2. changed line 8 from ".*" to "(.*)" --- public/.htaccess | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/.htaccess b/public/.htaccess index d554246d..680e1a5e 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -5,12 +5,12 @@ RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d -RewriteRule .* - [L] +RewriteRule (.*) - [L] # if request is no valid file NOR directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # if static asset do not do anything -RewriteRule (.*)(css|js|html|png|jpe?g|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map)$ - [NC,L,R=404] +RewriteRule (.*)(css|js|html|png|jpe?g|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map) - [NC,L,R=404] # everything else should be redirected to /index.html so it can be routed by it RewriteRule (.*) /index.html [L] From 6ac3a49db25953f2b29c6b69714a1d54533e2751 Mon Sep 17 00:00:00 2001 From: MartinH0 Date: Fri, 31 Jan 2020 01:36:17 +0100 Subject: [PATCH 10/10] Updated nginx.conf (optimization for future) 1. changed location from "~" (case sensitive!) to "~*" (case insensitive!) to also match uppercase static assets. (http://nginx.org/en/docs/http/ngx_http_core_module.html#location) 2. added regex "jpe?g" to match "jpg" and "jpeg" in one command. --- config/docker/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/docker/nginx.conf b/config/docker/nginx.conf index ddc24af8..b401b0ee 100644 --- a/config/docker/nginx.conf +++ b/config/docker/nginx.conf @@ -5,7 +5,7 @@ server { index index.html; # When requesting static paths with extension, try them, and return a 404 if not found - location ~ .+\.(css|js|html|png|jpg|jpeg|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map) { + location ~* .+\.(css|js|html|png|jpe?g|gif|bmp|ico|json|csv|otf|eot|svg|svgz|ttf|woff|woff2|ijmap|pdf|tif|map) { try_files $uri $uri/ =404; }