Spirited Posted May 15, 2021 Posted May 15, 2021 This was just something I had to setup again recently and I thought I'd post it this time around. This snippet allows for any website utilizing .htaccess to be a go-get repository by redirecting traffic from go get commands (contains go-get=1 in the request) to GitLab or another git repository hosting website. So for example, rather than importing my projects from "gitlab.com/spirited/projectname", I'd use my domain "spirited.io/projectname". That allows me to either redirect human traffic to the project page on my website or redirect go import traffic to the actual repo.Link to most up-to-date: https://gitlab.com/-/snippets/2121085.htaccess # BEGIN GolangRedirect <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{QUERY_STRING} (^|&)go-get=1($|&) RewriteRule . /goimport.php [L] </IfModule> # END GolangRedirect goimport.php <?php $importpath = rtrim(strtok($_SERVER["REQUEST_URI"],'?'), '/'); $domain = 'spirited.io'; $githublink = 'https://gitlab.com/spirited'; $goImport = $domain . $importpath . ' git ' . $githublink . $importpath . '.git'; ?> <html> <head> <meta name="go-import" content="<?= $goImport; ?>"> <meta http-equiv="refresh" content="1;url=<?= $githublink . $importpath; ?>" /> </head> </html> Quote
wickedliving Posted May 17, 2021 Posted May 17, 2021 That's awesome! I don't have anything to actually do this on, but it's interesting! Quote
Omicron Posted May 18, 2021 Posted May 18, 2021 Couldn't you just create a 301 redirect using a htaccess rule? Quote
Spirited Posted May 18, 2021 Author Posted May 18, 2021 Couldn't you just create a 301 redirect using a htaccess rule?Yeah, that would be a better approach! Thanks for the suggestion. I'll look into doing that after work today. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.