Ramblings from MostlyChris

Tech stuff and a bit more

Browsing Posts published in March, 2009

This is a super simple site redirect. This, of course, can get much more complicated than what is shown here.

Place this in the apache configuration file (non-Plesk boxen) or in a .htaccess file.

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

—–
If you want to redirect a site using the httpd.conf file inside a VirtualHost container you can do it this way (requires mod_alias):

<VirtualHost *:80>
ServerName original.domain.name
Redirect permanent / http://redirected.site.com/
</VirtualHost>

—–
Here is a simple redirect to take http://domain.com to http://www.domain.com.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com$1 [R=301,L]

This needs to be placed in each VirtualHost container and modified for the domain you are serving in that VirtualHost.

——
You can add this rule to allow browsing to a page without using the page extension. Place this in a .htaccess file in the directory.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

Replace the .html extension with whatever extension you are trying to remove from the filename.

Use this little one liner to grab the number of hits from the apache access logs.

DATE=`date +%d.%b.%Y`':';for i in `lsof -p $(ps faxwwwu|awk '$1 ~ /^root$/ && $11 ~ /httpd$/ {print $2|"head -1"}' )| awk '$9 ~ /access_log$/ {print $9| "sort -u"}'`; do echo "——-"$i"——"$DATE;awk '$4 ~ /^.'$DATE'/ {hit[substr($4,2,2)"\t"substr($4,14,2)"."substr($4,17,1)]++;ip[$1]++} END { for (i in hit) { print hit[i]"\t"i|"sort -k 3 -g"}; print ""}' $i;done

You can also grab a sorted list of IP addresses accessing sites by doing using this one liner.

DATE=`date +%d.%b.%Y`;for i in `lsof -p $(ps faxwwwu|awk '$1 ~ /^root$/ && $11 ~ /httpd$/ {print $2|"head -1"}' )| awk '$9 ~ /access_log$/ {print $9| "sort -u"}'`; do echo "——-"$i"——"$DATE;awk '$4 ~ /^.'$DATE'/ {hit[substr($4,2,2)"\t"substr($4,14,2)"."substr($4,17,1)]++;ip[$1]++} END { for (i in hit) { print hit[i]"\t"i|"sort -k 3 -n"}; print "";  for (i in ip) {print ip[i]"\t"i|"sort -n"}}' $i;done

Recently, I ran into an error while attempting to install a PECL package on a Redhat 5.3 64bit server.

—-
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 23040 bytes) in /usr/share/pear/PEAR/Builder.php on line 263
—-

I checked the memory limit setting in /etc/php.ini and it was set for 16M so that wasn't the problem. This is happening because PECL requires more memory on a 64bit box than a 32bit one. Incidentally, this works fine on 32bit OS's.

There are a couple of ways to get around this. The first would be to place the following at the top of the /usr/share/pear/pearcmd.php file:

ini_set('memory_limit', '16M');

Alternatively, you could could add the following to /usr/bin/pecl:

-d memory_limit=16M

16M should be plenty. However, if you still don't have enough memory then up the number to 32M. If that isn't enough, something else is going on.