Forum Moderators: phranque
<directory "/home/example/public_html">
AddType application/x-httpd-php .html .xhtml
AllowOverride None
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName example.com
CheckSpelling On
RewriteEngine on
# Externally redirect direct client requests for index.xyz to "/" in same directory
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/]+/)*)index\.([xs]?html?¦php[456]?)(\?[^\ ]*)?\ HTTP/
RewriteCond %1 !^(forum¦oea_new¦oea)/
RewriteRule /?index\.([xs]?html?¦php[456]?)$ http://www.example.com/%1? [R=301,L]
#
# Externally redirect direct client requests for URLS with "page" file extensions
# to extensionless URLs
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/]+/)*[^./]+)\.([xs]?html?¦php[456]?)(\?[^\ ]*)?\ HTTP/
RewriteCond %1 !^(forum¦oea_new¦oea)/
RewriteRule \.([xs]?html?¦php[456]?)$ http://www.example.com/%1? [R=301,L]
#
# Externally redirect requests for non-blank, non-canonical hostname to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.(beta\.)?example\.com)?$
RewriteRule /(.*) http://www.example.com/$1 [R=301,L]
###############################################
# Redirect to remove double slash within URL-path
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule /. http://www.example.com%1/%2 [R=301,L]
#
# Redirect to remove multiple slashes before URL-path
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ //+([^\ ]*)
RewriteRule /.* http://www.example.com/%1 [R=301,L]
################################################
#######################################################
#
# Return 403-Forbidden response for included-object requests with non-blank off-site referrers
RewriteCond %{HTTP_REFERER} !^(https?://(www\.)?(beta\.)?example\.com(/.*)?)?$ [NC]
RewriteRule \.(jpe?g¦gif¦bmp¦png¦ico¦css¦js)$ - [NC,F]
#
# Skip the following three rules if the requested URL-path has a file extension, if it is
# blank (i.e. a "homepage" request), or if it exists as a directory when a slash is appended
RewriteCond $1 \.[a-z0-9]+$¦^$ [NC,OR]
RewriteCond %{REQUEST_FILENAME}/ -d
RewriteRule /(.*) - [S=3]
#
# Internally rewrite extensionless URL request to existing .html file
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule /(.+) /$1.html [L]
#
# Internally rewrite extensionless URL request to existing .xhtml file
RewriteCond %{REQUEST_FILENAME}.xhtml -f
RewriteRule /(.+) /$1.xhtml [L]
#
# Internally rewrite extensionless URL request to existing .php file
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule /(.+) /$1.php [L]
ErrorDocument 404 /404.php
</directory>
<directory "/home/example/public_html/forum">
Options -MultiViews
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule . /forum/index.php [L]
</directory>
If you opt to use the slashless <Directory> path or no <Directory> container at all, then the two "remove multiple slashes" rules devolve to a single, simpler rule:
# Redirect to remove double slashes in URL-paths
RewriteRule ^(.*)//(.*)$ http://www.example.com%$/$2 [R=301,L]
I also suggest that you use <Limit PUT DELETE> and <LimitExcept PUT DELETE> instead of using the construct you're using above; Otherwise, you're leaving quite a few HTTP methods without any defined access policy. Note also that you can move the "Order" directive above these <Limit> containers -- No need to repeat it if it's the same in both cases. Also, no need to "Deny from all" if you're just going to turn around and "Allow from all" on the very next line -- Shorter code is better!
Jim
Something unexpected happened when I distilled this into the httpd.conf... The server re-designed all my rules!... I hit the panic button and restored the file from a backup, and re-distilled it, so I'm back to where I was before I began... but I saved the re-designed version to post here.
Why did the server change everything to look like this? Are all the rules in place, doing as they were in the original design?...
<Directory "/home/example/public_html">
AddType application/x-httpd-php .html .xhtml
AllowOverride None
AuthName example.com
CheckSpelling On
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/]+/)*)index\.([xs]?html?如hp[456]?)(\?[^\ ]*)?\ HTTP/
RewriteCond %1 !^(forum她ea_new她ea)/
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/]+/)*[^./]+)\.([xs]?html?如hp[456]?)(\?[^\ ]*)?\ HTTP/
RewriteCond %{HTTP_HOST} !^(www\.(beta\.)?example\.com)?$
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ //+([^\ ]*)
RewriteCond %{HTTP_REFERER} !^(https?://(www\.)?(beta\.)?example\.com(/.*)?)?$ [NC]
RewriteCond $1 \.[a-z0-9]+$回$ [NC,OR]
RewriteCond %{REQUEST_FILENAME}/ -d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_FILENAME}.xhtml -f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule /?index\.([xs]?html?如hp[456]?)$ http://www.example.com/%1? [R=301,L]
RewriteRule \.([xs]?html?如hp[456]?)$ http://www.example.com/%1? [R=301,L]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
RewriteRule /. http://www.example.com%1/%2 [R=301,L]
RewriteRule /.* http://www.example.com/%1 [R=301,L]
RewriteRule \.(jpe?g夙if在mp如ng夷co圭ss夸s)$ - [NC,F]
RewriteRule ^(.*) - [S=3]
RewriteRule ^(.+) /$1.html [L]
RewriteRule ^(.+) /$1.xhtml [L]
RewriteRule ^(.+) /$1.php [L]
ErrorDocument 404 /404.php
</Directory>
<Directory "/home/example/public_html/forum">
Options -MultiViews
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule . /forum/index.php [L]
</Directory>
[Mon Nov 30 10:53:10 2009] [debug] mod_rewrite.c(1788): [client 123.456.789.000] mod_rewrite's internal redirect status: 0/10.
[Mon Nov 30 10:53:11 2009] [info] [client 123.456.789.000] (32)Broken pipe: core_output_filter: writing data to the network
This is way beyond me. Is there anything in my htaccess that might be causing this? The htaccess worked fine when I was on 32 bit... but since changing to 64 bit OS, things have started going wrong.
This search [google.com] for the exact error message may give you some useful info.
Jim
In fact, since posting the above, it ocurred to me that the forum siftware was using the path_info method for re-writing, so I changed it to query string method and I'll see what happens. If the problem persists, I'll selectively remove rules as you suggest.
Incidentally, the following errors were in Apache logs, do they mean anything to you?...
*** glibc detected *** /usr/local/apache/bin/httpd: free(): invalid pointer: 0x0000000011c2a880 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3bc34722ef]
/lib64/libc.so.6(cfree+0x4b)[0x3bc347273b]
/usr/local/apache/lib/libapr-1.so.0(apr_allocator_destroy+0x45)[0x2b2e10dd19ee]
/usr/local/apache/lib/libapr-1.so.0(apr_pool_destroy+0x13f)[0x2b2e10dd26d2]
/usr/local/apache/bin/httpd[0x4d59ed]
/usr/local/apache/bin/httpd[0x4d5cfb]
/lib64/libpthread.so.0[0x3bc3c0e7c0]
/lib64/ld-linux-x86-64.so.2[0x3bc3008e02]
/lib64/ld-linux-x86-64.so.2[0x3bc3009212]
/lib64/ld-linux-x86-64.so.2[0x3bc300cd15]
/lib64/ld-linux-x86-64.so.2[0x3bc3012892]
/usr/lib64/libkrb5.so.3[0x3bcc419597]
/usr/lib64/libkrb5.so.3[0x3bcc4191df]