Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule without File Extensions

         

DonX

6:01 pm on Jul 11, 2006 (gmt 0)

10+ Year Member



I have recently moved an existing website to a new hosting company but have found my rewrite rules no longer function.

I used to use lines such as "RewriteRule ^folder1/(.*)$ /folder2/index.php?title=$2 [L,QSA]" within my .htaccess file, but now these pages bring me straight to a 404 error page and I have been unable to find any information on what the problem might be.

After some testing I have discovered that some url formats are not being accepted by the server - I cannot visit directories that do not end in a forward slash or view files that do not have a file extension, for example:

[mysite.com...]
[mysite.com...]

I really hope someone might know the cause of this unusual file extension issue so I might be able to find a workaround and get my website running again.

Thank you.

jdMorgan

7:18 pm on Jul 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I cannot visit directories that do not end in a forward slash

According to URL-naming conventions, directory names *must* end in a slash; Otherwise, the request is for an extensionless *file*.

Examples:
http://example.com -- HTTP protocol error, typically redirected to http://example.com/
http://example.com/ -- Request for directory index of root directory.
http://example.com/foo -- Request for the file 'foo' in root directory.
http://example.com/foo.jpg -- Request for the file 'foo.jpg' in root directory.
http://example.com/foo/ -- Request for directory index of foo subdirectory.
http://example.com/foo/bar -- Request for file 'bar' in foo subdirectory.
http://example.com/foo/bar.gif -- Request for file 'bar.gif' in foo subdirectory.

Apache has a work-around for URL-naming errors such as missing trailing slashes on directory requests, specifically, the mod_dir [httpd.apache.org] module. It sounds like this module is not installed or enabled on your new server; Ask your hosting provider about this.

Be warned that relying on mod_dir (or as an alternate possibility, mod_negotiation) to 'fix-up' malformed requests can result in significant performance reduction for a busy server. It is best to stick to standard URL-naming conventions to avoid this, at least on your own pages where you can control the URLs used in links. This is because the server must first check to see if the no-trailing-slash URL resolves to an existing file. If not, it must then append a trailing slash, and check again to see if that resolves to an existing directory index. If not, it must then remove the trailing slash and invoke the standard error-handing process. So, additonal code must be executed and an extra call must be made to the filesystem to do extra checking for every HTTP request to the server.

So while installing mod_dir will likely fix your problem, it would be far more efficient to use proper URL-naming on your site to avoid having to run it very often.

Refs:
RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax [faqs.org]
Hypertext Transfer Protocol -- HTTP/1.1 [w3.org]

Jim

DonX

7:30 pm on Jul 13, 2006 (gmt 0)

10+ Year Member



Thank you very much for your quick and helpful response. My website is now up and running again :)