diff options
| author | Christian Cleberg <[email protected]> | 2025-11-11 22:49:13 -0600 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2025-11-11 22:49:13 -0600 |
| commit | 51a7a02f0c96d49b68fbcc155414c218207fa270 (patch) | |
| tree | 845af8aad0e8769352efc02fcd1044eed9cc1ec1 /content/blog/2022-12-07-nginx-wildcard-redirect.org | |
| parent | 7d3e80ebf1dc770eac0e21890b74f18ba2d15a6b (diff) | |
| download | cleberg.net-51a7a02f0c96d49b68fbcc155414c218207fa270.tar.gz cleberg.net-51a7a02f0c96d49b68fbcc155414c218207fa270.tar.bz2 cleberg.net-51a7a02f0c96d49b68fbcc155414c218207fa270.zip | |
fix grammar in 2022 posts
Diffstat (limited to 'content/blog/2022-12-07-nginx-wildcard-redirect.org')
| -rw-r--r-- | content/blog/2022-12-07-nginx-wildcard-redirect.org | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/content/blog/2022-12-07-nginx-wildcard-redirect.org b/content/blog/2022-12-07-nginx-wildcard-redirect.org index 2e54fae..cc15887 100644 --- a/content/blog/2022-12-07-nginx-wildcard-redirect.org +++ b/content/blog/2022-12-07-nginx-wildcard-redirect.org @@ -5,18 +5,18 @@ * Problem -I recently migrated domains and replaced the old webpage with a simple -info page with instructions to users on how to edit their bookmarks and -URLs to get to the page they were seeking. +I recently migrated domains and replaced the old webpage with a simple info page +with instructions to users on how to edit their bookmarks and URLs to get to the +page they were seeking. -This was not ideal as it left the work up to the user and may have -caused friction for users who accessed my RSS feed. +This was not ideal as it left the work up to the user and may have caused +friction for users who accessed my RSS (Really Simple Syndication) feed. * Solution -Instead, I finally found a solution that allows me to redirect both -subdomains AND trailing content. For example, both of these URLs now -redirect properly using the logic I'll explain below: +Instead, I finally found a solution that allows me to redirect both subdomains +AND trailing content. For example, both of these URLs now redirect properly +using the logic I'll explain below: #+begin_src txt # Example 1 - Simple base domain redirect with trailing content @@ -28,19 +28,19 @@ https://libreddit.domain1.com/r/history/comments/7z8cbg/new_discovery_mode_turns https://libreddit.domain2.com/r/history/comments/7z8cbg/new_discovery_mode_turns_video_game_assassins/ #+end_src -Go ahead, try the URLs if you want to test them. +Go ahead, try the URLs (uniform resource locators) if you want to test them. ** Nginx Config -To make this possible. I needed to configure a proper redirect scheme in -my Nginx configuration. +To make this possible. I needed to configure a proper redirect scheme in my +Nginx configuration. #+begin_src sh doas nano /etc/nginx/http.d/domain1.conf #+end_src -Within this file, I had one block configured to redirect HTTP requests -to HTTPS for the base domain and all subdomains. +Within this file, I had one block configured to redirect HTTP requests to HTTPS +for the base domain and all subdomains. #+begin_src conf server { @@ -60,10 +60,9 @@ server { } #+end_src -For the base domain, I have another =server= block dedicated to -redirecting all base domain requests. You can see that the =rewrite= -line is instructing Nginx to gather all trailing content and append it -to the new =domain2.com= URL. +For the base domain, I have another =server= block dedicated to redirecting all +base domain requests. You can see that the =rewrite= line is instructing Nginx +to gather all trailing content and append it to the new =domain2.com= URL. #+begin_src conf server { @@ -79,17 +78,16 @@ server { } #+end_src -Finally, the tricky part is figuring out how to tell Nginx to redirect -while keeping both a subdomain and trailing content intact. I found that -the easiest way to do this is to give it a =server= block of its own. +Finally, the tricky part is figuring out how to tell Nginx to redirect while +keeping both a subdomain and trailing content intact. I found that the easiest +way to do this is to give it a =server= block of its own. -Within this block, we need to do some regex on the =server_name= line -before we can rewrite anything. This creates a variable called -=subdomain=. +Within this block, we need to do some regex on the =server_name= line before we +can rewrite anything. This creates a variable called =subdomain=. -Once the server gets to the =rewrite= line, it pulls the =subdomain= -variable from above and uses it on the new =domain2.com= domain before -appending the trailing content (=$request_uri=). +Once the server gets to the =rewrite= line, it pulls the =subdomain= variable +from above and uses it on the new =domain2.com= domain before appending the +trailing content (=$request_uri=). #+begin_src conf server { @@ -105,15 +103,15 @@ server { } #+end_src -That's all there is to it. With this, I simply restarted Nginx and -watched the redirections work in-action. +That's all there is to it. With this, I simply restarted Nginx and watched the +redirections work in-action. #+begin_src sh doas rc-service nginx restart #+end_src -Looking back on it, I wish I had done this sooner. Who knows how many -people went looking for my sites or bookmarks and gave up when they saw -the redirect instructions page. +Looking back on it, I wish I had done this sooner. Who knows how many people +went looking for my sites or bookmarks and gave up when they saw the redirect +instructions page. Oh well, it's done now. Live and learn. |
