Mod_rewrite & 'file name too long'

I use mod_rewrite to send unknown requests to index.php:

RewriteEngine On
RewriteRule (.+) /index.php

The purpose is to let users add a string of article numbers to the url and have index.php process them by looking at $_SERVER[‘REQUEST_URI’], for example:,00349587,0,1,45878

This works fine until that string of numbers is longer than 255 chars. Then error.log says: “File name too long”. Access.log shows it’s a 403 error. The displayed web page is the standard 403 error page, that says “Forbidden… Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument.”

I tried to set an ErrorDocument for 403 errors in .htaccess but it’s ignored. Does anyone know of any way to redirect or rewrite despite a file name too long error? I really just want it to ignore the whole url and let index.php handle everything.

If I use a ‘?’ to make the url like this:,00349587,0,1,45878

Then it can handle as much as any GET request. Maybe you say that’s silly, but I’d rather not require the ‘?’ if I don’t have to.

Any ideas?


Is the URL meant for manually editing by users or will you be dynamically assembling them? Just as a forewarning, forcing users to “Navigate By Numbers” is extremely tedious and somewhat counter-intuitive for them.

This is also not a good thing for Search Engine Optimization if that will be a concern.

I’d possibly do something like:


# Rule for a query with 7 arguments; the page 6 add'l args. RewriteRule ^([^-] )-([^-] )-([^-] )-([^-] )-([^-] )-([^-] )-([^-] )\.htm$ index.php?page=$1&aid1=$2&aid2=$3&aid3=$4&aid4=$5&aid5=$6&aid6=$7 [L,NC,NS]Then, you can use URLs such as this on the backend:

…which will be accessible like this on the front-end:

Hope that sparks something for you,


  • Alar

What’s the purpose of including “.htm” at the end? There’s no reason for it, espeically since you’re just ignoring it in the rewrite rules anyway.

If you want useful replies, ask smart questions.

Look carefully … the .htm isn’t being ignored.

…it’s an integral part of the URL.

Your suggestion has the same problem.

When this:
is longer than 255 chars, it will give the same ‘file name too long’ error.


How is it an integral part of the URL if it isn’t being used? Look at the rewrite rule you wrote; where is the “.htm” being used in the rewrite target? Wouldn’t it work exactly the same without the “.htm”? (answer: yes)

In other words, why require a file extension when you’re not actually calling a file directly? There are no actual “.htm” files in use, you’re just calling a PHP script with a query string. Why use an extension at all in a situation like this?

If you want useful replies, ask smart questions.

I see your point.

It isn’t. And it wouldn’t be as that side of the ‘equation’ (if you will) handles the arguments that were passed in the URL, not the file extension.

For Search Engine Optimization purposes, of course. :wink:

That is exactly my point: that it’s irrelevant to the end result.

(and I’m quite familiar with how mod_rewrite works, but thanks for the explanation anyway)

Regarding SEO, can you find me one source that says file extensions are important to even a single well-known search engine? And that this would help a bit when the rest of the URL is a string of meaningless characters?

Words appearing in URLs are important, yes, but file extensions – be they htm, html, php, cgi, pl, or wtf – are implementation details that are entirely unrelated to the content of a particular page. They are exactly the same as the aforementioned meaningless characters in that they don’t mean a thing to anyone but the site developer.

URLs on my sites don’t use file extensions at all, even when they refer to an actual file on the server. There’s no need for it.

If you want useful replies, ask smart questions.

Even if I could, I suspect it would be pointless; you’re taking an argumentative stance throughout. :slight_smile: How about you just post your sources to the contrary and that will be fine.

Yes, words are important, this we know. But I don’t find anything that says extensions are not looked at. I think at least some users like to know what types of pages they’re viewing, so the developer argument is a bit over the top. The extensions can be used to hint at dynamic content to average users also: php>html, for example, as not every web surfer understands or knows about URL rewriting and might equate htm* as static content.

I think it’s great that you found a way that satisfies your needs, , but don’t think it was worth hijacking the thread over.

  • Alar