Need to get the RSS feed from a twitter user’s status updates? No problem! Here’s how you do it.
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=xxxxx
replace xxxxx with the twitter username
Share your thoughts
Let’s say you want to redirect www.yourdomain.com to yourdomain.com for SEO reasons. The best way to accomplish this is in your apache config file. Sure, you can use .htaccess, but Apache will have to literally open the file for every request. Better performance to just do it in the httpd.conf file. Here’s an example of how I add new domains to apache.
<VirtualHost 216.246.34.88>
<Directory /www/boldtwww/example.com/htdocs>
AllowOverride AuthConfig FileInfo All
</Directory>
ServerName example.com
ScriptAlias /cgi-bin/ /www/boldtwww/example.com/cgi-bin/
DocumentRoot /www/boldtwww/example.com/htdocs
ErrorLog /var/log/httpd/example.com-error_log
CustomLog /var/log/httpd/example.com-access_log combined
</VirtualHost>
<VirtualHost 216.246.34.88>
<Directory /www/boldtwww/example.com/htdocs>
AllowOverride AuthConfig FileInfo All
</Directory>
ServerName www.example.com
RedirectPermanent / http://example.com/
ScriptAlias /cgi-bin/ /www/boldtwww/example.com/cgi-bin/
DocumentRoot /www/boldtwww/example.com/htdocs
ErrorLog /var/log/httpd/example.com-error_log
CustomLog /var/log/httpd/example.com-access_log combined
</VirtualHost>
Share your thoughts
Let’s say you have an old site which used to have a lot of random question marks and values in the url which you no longer need.
If you are using php, your site very well may load these pages with a 200OK, possibly creating duplicate content issues.
Here’s a .htaccess snippit to strip any values off an URL:
RewriteCond %{QUERY_STRING} !=”"
RewriteRule ^(.*)$ /$1? [R=301,L]
Example:
http://whateverdomain.com/?postid=12334 would become http://whateverdomain.com/
This is very useful for stripping off tracking garbage appended by popular social sites.
Share your thoughts
vi has a powerful search and replace function. Let’s say you have a long list of keywords which you want to append and prepend text to. In this example, we will add bracket to the beginning and the end of each line.
:%s/^/[
:%s/$/]
It’s basically sed being invoked from within vi
Share your thoughts
Is parsing PHP in web pages that end in .html or .htm, possible? Absolutely!
If you’re hosted on an Apache webserver, just edit the .htaccess file in your documentroot.
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Apache is now parsing PHP in .html for that website.
Share your thoughts
You can invoke “adduser” command in FreeBSD in order to create new user. Adduser will prompt you for user info like name, uid, gid, shell environment and etc. But sometime we would like to create user access through Bash script. “useradd” command is the good way to do it. In Linux, using “useradd” is pretty common for creating new user access. You can also use “useradd” in FreeBSD, but not directly invoke “useradd” command. Below is the sample of creating new user in FreeBSD with “useradd”.
Replace username with the desired username, replace Firstname Lastname with the user’s real name, and replace homedir with the user’s name.
# pw useradd username -c ‘Firstname Lastname’ -d /home/homedir -s /usr/local/bin/bash
The new account is created, but don’t forget to use passwd to set a pass
# passwd username
You can run other command like “userdel”, “usermod”, “usershow”, “groupadd”, “groupdel”, “groupmod”, “lock”, “unlock” on FreeBSD by using the “pw” command.
Share your thoughts
It’s always easy to ssh login without a password with public host key authorization on any unix machine.
First you’ll need to create your local public key. This is the public end of a local public / private pair that you’ll share with the remote server to identify you.
ssh-keygen -t dsa (on your local machine)
Second you’ll need to copy this key to the remote machine using a command such as:
scp ~/.ssh/id_dsa.pub user@yourserver.com:~
Lastly, log into the remote machine via ssh (using your password for the last time!) and use this command to add the newly generated key to the list of authenticated keys:
cat id_dsa.pub >> .ssh/authorized_keys
You’ll also probably want to delete the original key as well.
rm id_dsa.pub
A copy of your key is now on the remote server as an authorized keys and any incoming ssh connection originating from the local machine will key match and connect with the host key authentication instead of having to type in a password.
Share your thoughts
Open Terminal and enter the following code:
ssh -D 8080 -f -C -q -N admin@server1.cluebin.com
This opens the tunnel by spawning an OpenSSH client into the background which will listen on port 8080, and will forward the traffic to server1.cluebin.com.
Then, you open FireFox or your favorite brower, and in the about:config page change the following 6 items to the following values:
network.proxy.no_proxies_on : localhost, 127.0.0.1, 192.168.0.0/24, .yourcompany.com
network.proxy.socks : 127.0.0.1
network.proxy.socks_port : 8080
network.proxy.socks.remote_dns : true
network.proxy.socks_version : 5
network.proxy.type : 1
Share your thoughts
I do this on just about every machine I roll out. Needed a handy place to keep the code:
cd /usr/ports/databases/mysql51-server/
make install
/usr/local/bin/mysql_install_db
chown -R mysql /var/db/mysql/
chgrp -R mysql /var/db/mysql/
/usr/local/bin/mysqld_safe –user=mysql &
/usr/local/bin/mysqladmin -uroot password somenewpassword
echo 'mysql_enable="YES"' >> /etc/rc.conf
Share your thoughts
Say you have an odd URL pattern which you want to get a 404 reply before it hits your CMS.
Add this to your .htaccess file, and obviously replace the word something with your pattern.
The line containing [OR] can be duplicated or deleted depending on if you have multiple patterns, or a single pattern.
RewriteEngine On
RewriteCond %{REQUEST_URI} /something-else-optional/ [OR]
RewriteCond %{REQUEST_URI} /something/
RewriteRule .* /404.php [L]
and then create 404.php in your DocumentRoot, and place the following at the very top on line 1, inside php tags.
header("HTTP/1.0 404 Not Found");
Share your thoughts