Forum Moderators: phranque

Message Too Old, No Replies

Migrating my htaccesss file to httpd.conf

         

Asia_Expat

10:02 pm on Nov 26, 2009 (gmt 0)

10+ Year Member



Ages ago, I posted a question how to do this but the thread is too old to continue now.... but I think I've got this figured out. I've added the / in front of regular expressions... but where there is a \ I've not turned it into a /\
Also, in the forum part right at the end, I've not added the / to the rule as I believe it's not necessary? Have I got this right?...

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

jdMorgan

11:13 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In a server config file context outside of any <Directory> container, you need to change the code and add slashes, etc. However, if you put the code in a <Directory> container and specify .../public/html/ as the directory (ending with a slash), then you don't really need to change the code.

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]

Note that I'd recommend anchoring your patterns, just on principle. So "/(.*)" becomes "^/(.*)$" and "/(.+)" becomes "^/(.+)$" -- This may save a little time for the regex parser trying to figure out the 'best match' when you know you just want the 'whole match'...

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

Asia_Expat

7:15 am on Nov 27, 2009 (gmt 0)

10+ Year Member



Re the limit GET POST stuff, I just canned it all, as it was some kind of rubbish added by FrontPage extentions, long before I removed FrontPage from my server altogether.

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>

jdMorgan

2:11 pm on Nov 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No idea... Ask your host. Whatever it did to your rules, the result certainly won't work.

Jim

Asia_Expat

12:54 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



Going off at a tangent a little here... I've been having major overload problems. Every few hours, the server tries to grind itself to dust, and the following appears in the error logs...

[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.

jdMorgan

3:06 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this problem something that started after you changed the code? If so, then comment-out the non-critical rules one or a few at a time, and see if you can narrow-down the problem. You won't be able to comment out the last four rules since your site relies on them to function, but the canonicalization rules aren't critical.

This search [google.com] for the exact error message may give you some useful info.

Jim

Asia_Expat

4:27 pm on Nov 30, 2009 (gmt 0)

10+ Year Member



The code has been the same for ages. Problems began when my host changed my server to 64 bit architecture. Every few hours, the server overloads itself and it was exhasserbated by some DoS incidents I've been having recently. It only seems to be happening with forum threads (which are re-written FURLs), so that's the directory/set of directives I'm focusing on...

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]

jdMorgan

5:34 pm on Nov 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, not really, but you could look them up. Based on the reported modules, it looks like there may be a bug in the 64-bit memory-management function called by glibc.

Certainly something to forward to your host for a look-see..

Jim