Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My url scheme is /foo/var1-var2-var3.../bar

I am using these mod_rewrite rules:

RewriteBase /foo/
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^ index.php [PT,L]

If the length of the string 'var1-var2...' is greater than 257 characters then an error 403 Forbidden and a 404 are returned. However, if the length of the 'var1-var2...' string is 257 characters or less and subsequently followed by a slash the length of the remaining url may be any length. How does one overcome this limit?

share|improve this question

migrated from stackoverflow.com Mar 8 '10 at 17:19

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 5 down vote accepted

You are running into a limitation of the underlying file system.

Take a look at File System Limits. You will see that most have a Maximum filename length of 255 bytes. Thus, when apache and/or your rewrite rule checks if the file exists an error is returned to apache by the operating system.

With Apache, if you put rules such as this in the .htaccess file, it's too late to work around the problem. Apache will have already attempted to stat the long filename thus throwing the file system error '(36)File name too long', returning a 403 error.

I see two options:

  1. Change the URL format of your application to a max of 255 characters between each slash.
  2. Move the Rewrite rules into the apache virtual host config and remove the REQUEST_FILENAME.
share|improve this answer
    
If a .htaccess file doesn't include {REQUEST_FILENAME}, but still is returning a 403, could this still be the problem? ( serverfault.com/questions/140852/… ) –  philfreo May 17 '10 at 16:45
    
You must move the rewrite rules into the apache config. This is the only way to retain the functionality and work around the problem. –  h0tw1r3 Jul 23 '11 at 15:32
    
When moving rules from .htaccess to apache virtual host config, you need to change %{REQUEST_FILENAME} => %{DOCUMENT_ROOT}%{REQUEST_FILENAME} and also add slash to the start of your URL patterns, e.g. not RewriteRule ^abc ... but RewriteRule ^/abc .... You gotta love the mod_rewrite's straightforwardness... –  ash108 Oct 14 '13 at 17:02
1  
"Move the Rewrite rules into the apache virtual host config" part is golden: it actually works when implemented properly, unlike many other workarounds I've tried. –  ash108 Oct 14 '13 at 17:04

Your Answer

 
discard

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.