I'm using mod_rewrite to rewrite URLs like this:
http://example.com/1,2,3,4/foo/
By doing this in .htaccess:
RewriteEngine On
RewriteRule ^([\d,]+)/foo/$ /foo.php?id=$1 [L,QSA]
It works fine, except for when "1,2,3,4" turns into a string longer than 255 characters, Apache returns a "403 Forbidden".
There is no problem visiting foo.php?id=1,2,3,4
directly, even with a very long id string, however this isn't an option for me.
Is there some Apache or other setting I should tweak?
UPDATE: I turned RewriteLog on with RewriteLogLevel 9. With a short id string, I get several lines in my log file. But when the id string is greater than 255 chars., nothing is logged (seems as though mod_rewrite isn't even executing?).
If you find this question interesting/helpful, please upvote it.
Do you think you are running into a limitation of the file system?
May be the max filename length is of 255 bytes and when apache or the mod_rewrite rule checks if the file exists an error is returned to apache by the operating system.
If you put some rule in your .htaccess file, It's too late to work around the problem. Apache will have already tried to stat the filename and thrown file system error '(36)File name too long', returning a 403 error.
Maybe you could change the URL pattern inside your app. to a max of 255 chars from slash to slash.
EDIT: look here for a detailed answer to this issue. I borrowed mine from there.
There's a similar question about this limit here:
I don't know if you're using REQUEST_FILENAME somewhere in you .htaccess configuration, so don't know if the provided solution is going to work.
Definitely an interesting question. Do you run mod_security and if so, tried without it? Perhaps it simply doesn't like long path names or long path names with unencoded commas in them? ^^
Though it instinctively feels more like a limit on the url path or at least individual segments of it or the underlying filesystem interpretation of it as GmonC wrote. That would also explain why the regular url with the long part in the query string works fine.
I think older ASP.NET used to have a request path limit of ~260 characters or something as well.
Are you willing to change http servers? Consider nginx instead of apache then.
And use http://wiki.nginx.org/NginxHttpRewriteModule