Archive for the 'unix' Category
Force the Use of a domain

Do you find yourself needing to redirect a website to use only one domain. For example you have www.example.com, example.com, example1.com, www.example1.com, www.example2.com but you always what www.example.com to show up.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

Here is a real world example.

# Use one domain

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

Recursive Find and Replace

At my job, I often need to recursivly find and replace certain strings. I always fumble around for the syntax, here is the syntax so I don’t forget

find ./ -type f -exec sed -i 's/ReplaceThis/WithThis/' {} \;

And you can add all of the custom stuff to find like name if you want, here is a real world example.

find ./ -name '*php' ! -name '.*' -exec sed -i 's/<noindex follow>/<!--sphider_noindex-->/' {} \;