Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm replacing index.cgi of gitweb with a static index.html page.

However I don't want links to gitweb repositories to break, such as;

My non-working .htaccess currently looks like:

DirectoryIndex index.html index.php
RewriteCond %{QUERY_STRING} p
RewriteRule ^/ /index.cgi

What am I missing?

share|improve this question
When you say "non-working", what exactly do you see? The only obvious thing I see missing is RewriteEngine on. – Ladadadada Nov 29 '11 at 9:03
Oh, also in a directory context (i.e. In a .htaccess file) URIs don't start with a slash. In the server context they do. – Ladadadada Nov 29 '11 at 9:06

By my reading of the RewriteRule docs ("What is matched?" box), if your RewriteRule is in a Directory section or .htaccess file, then the leading / will be stripped away, so the pattern in your rule won't match. You could try replacing the pattern by just ^, i.e.

RewriteRule ^ /index.cgi
share|improve this answer
Request exceeded the limit of 10 internal redirects due to probable configuration error. :( – hendry Nov 29 '11 at 10:11

With that rule you will never be able to access the index.html page as the redirect will match anything.

You would need to do something along the lines of

RewriteCond %{QUERY_STRING}      ^$
RewriteRule ^/                   /index.html [L]
RewriteRule ^/                   /index.cgi

Which should work out similar to 'if you don't have a querystring go to index.html, otherwise go to index.cgi and pass the rest of the string along too!'

share|improve this answer

It will match any URI that is not index.cgi or index.html beginning with a p query string and rewrite it to your cgi.

RewriteCond %{QUERY_STRING} ^p
RewriteRule !(index.cgi|index.html) /index.cgi [L]

The L option means that Apache stops processing rewrite rules.

share|improve this answer
Stangely I get a 404 The requested URL /srv/www/wac2tests/index.cgi was not found on this server. – hendry Nov 29 '11 at 10:56
but x220:~$ file /srv/www/wac2tests/index.cgi /srv/www/wac2tests/index.cgi: symbolic link to `/srv/http/gitweb/gitweb.cgi' – hendry Nov 29 '11 at 10:56
That's not a URL, that's a file path. I'm not sure why it's doing that. I've seen Apache do that before but I can't remember what caused it. – Ladadadada Nov 29 '11 at 11:04
Nice, short and sweet! QSA is unneeded and won't match however. – syserr0r Nov 29 '11 at 11:08
actually this seems to redirect and file query string, even on say /ui/?foobar to /index.cgi... urgh :( – hendry Nov 30 '11 at 6:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.