mod_rewrite & 'file name too long'

mod_rewrite & 'file name too long'

Posted by: shelves
Posted on: 2006-10-12 23:44:00

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

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
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:

http://domain.com/0003947534975,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:

http://domain.com/?0003947534975,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?

Terry


Re: mod_rewrite & 'file name too long'

Posted by: alarconcepts
Posted on: 2006-10-13 07:44:00

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.

In reply to:

I really just want it to ignore the whole url and let index.php handle everything.




I'd possibly do something like:

.htaccess

# 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:

http://www.yoursite.com/index.php?page=articles&aid1=012&aid2=123&aid3=234&aid4=345&aid5=456&aid6=567

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

http://www.yoursite.com/articles-012-123-234-345-456-567.htm



Hope that sparks something for you,

Cheers,

- Alar




Re: mod_rewrite & 'file name too long'

Posted by: kchrist
Posted on: 2006-10-13 09:32:00

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.

Re: mod_rewrite & 'file name too long'

Posted by: alarconcepts
Posted on: 2006-10-13 10:35:00

Look carefully .. the .htm isn't being ignored.

...it's an integral part of the URL.


Re: mod_rewrite & 'file name too long'

Posted by: shelves
Posted on: 2006-10-13 10:44:00


Your suggestion has the same problem.

When this:
http://www.yoursite.com/articles-012-123-234-345-456-567.htm
is longer than 255 chars, it will give the same 'file name too long' error.

Terry



Re: mod_rewrite & 'file name too long'

Posted by: kchrist
Posted on: 2006-10-13 11:03:00

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?


Re: mod_rewrite & 'file name too long'

Posted by: alarconcepts
Posted on: 2006-10-13 11:10:00

In reply to:

Your suggestion has the same problem.


I see your point.



Re: mod_rewrite & 'file name too long'

Posted by: alarconcepts
Posted on: 2006-10-13 11:16:00

In reply to:

Look at the rewrite rule you wrote; where is the ".htm" being used in the rewrite target?


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.

In reply to:

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?


For Search Engine Optimization purposes, of course. ;)

Edited by alarconcepts on 10/13/06 11:17 AM (server time).

Re: mod_rewrite & 'file name too long'

Posted by: kchrist
Posted on: 2006-10-13 12:29:00

In reply to:

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.


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.

Re: mod_rewrite & 'file name too long'

Posted by: alarconcepts
Posted on: 2006-10-13 13:00:00

In reply to:

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?


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

In reply to:

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.


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.

In reply to:

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.


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

Tags: mod rewrite