Skip to content

Instantly share code, notes, and snippets.

@samrocketman
Last active January 4, 2016 17:19
Show Gist options
  • Save samrocketman/8653436 to your computer and use it in GitHub Desktop.
Save samrocketman/8653436 to your computer and use it in GitHub Desktop.
A sample apache rewrite for checking for a gitlab cookie and redirecting a user accordingly. This goes in the gitlab virtualhost before the proxy and after RewriteEngine On..
#http://httpd.apache.org/docs/2.2/rewrite/intro.html#rewritecond
#http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
#http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
#Use NOT logic. If cookie doesn't exist then redirect. Otherwise, default behavior.
RewriteCond %{HTTP_COOKIE} !request_method
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/$ /public/ [NE,R,L]
@jaybe-jekyll
Copy link

  • Visitors default to Public repositories section.
  • Logged in users default to Dashboard section.
  • Logged out user default to Public repositories section.
location = / {
  if ($http_cookie !~* "request_method") {
    set $logic "N";
  }

  if ($is_args != "?") {
    set $logic "${logic}O";
  }

  if ($logic = "NO") {
    return 302 /public;
  }

  if ($http_cookie ~* "request_method=delete") {
    return 302 /public$is_args$args;
  }

  if ($logic = "N") {
    return 302 /public$is_args$args;
  }

  return 302 /dashboard$is_args$args;
}

@samrocketman
Copy link
Author

Serve a non-gitlab sub-URL.

  ########## serve non-gitlab sub-URL
  Alias /svn /var/www/html
  ##########

  #apache equivalent of nginx try files
  # http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
  # http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
  RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
  RewriteCond %{REQUEST_URI} !/svn.*
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment