0

Here is what I am trying to do:

  • When a file is requested from filesystem and it does not exist, rewrite the URL to /index.php?404
  • When file is requested and it does exist in filesystem, rewrite the URL to /index.php?file
  • In every other case rewrite the URL to /index.php?data

But I am getting 500 errors as a result, does anyone know where the problem might be? I have used RewriteEngine in the past, but it's still a bit confusing to me regarding how to use it for special cases like this.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} (.*\.([a-zA-Z]{2,4}))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php?404 [L]

RewriteCond %{REQUEST_FILENAME} (.*\.([a-zA-Z]{2,4}))$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* ./index.php?file [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php?data [L]
kingmaple
  • 4,200
  • 5
  • 32
  • 44
  • Note that the above system does work if I take the second condition out. This confuses me, since the regular expression itself is the same. – kingmaple Mar 13 '12 at 20:30
  • 1
    You have infinite rewrite loop. To solve -- add extra condition to not rewrite already rewritten URLs .. or at least ignore requests to index.php. P.S. How `L` flag works: http://stackoverflow.com/questions/6797998/rewriterule-last-l-flag-not-working – LazyOne Mar 13 '12 at 23:03
  • You're correct, it was a rewrite loop. I'd accept this as an answer if you make it an answer. – kingmaple Mar 14 '12 at 07:57

1 Answers1

1

You have infinite rewrite loop. To solve -- add extra condition to not rewrite already rewritten URLs .. or at least ignore requests to index.php.

One of the possible approaches:

# do not touch any requests to index.php
RewriteRule ^index\.php$ - [L]

P.S. How L flag works: RewriteRule Last [L] flag not working?

Community
  • 1
  • 1
LazyOne
  • 158,824
  • 45
  • 388
  • 391