Apache conf serving static files with question mark in filename

If you have files on your filesystem with ‘?’ question mark in them, for example:

index.html?q=somestring

This can occur when you have site-ripped a PHP based website with for instance wget or other tools. If you access an url with ‘?’ in it, the webserver will try to serve the string after the question mark as a query string. This will not work, since there is no PHP, and result will be that you always get the index.html file, not the file named: “index.html?q=somestring”

This can be solved with an Apache rewritecond/rule configuration. Apache can be configured so that the ‘?’ is interpreted as part of the filename and not serving a query string.

Here is an example:
Directory "/var/www/html/path/to/files/";
AddType text/css .css?J
RewriteEngine On
RewriteBase /sites
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ $1\%3F%{QUERY_STRING}? [L]

Convert multiple files from latin1 to utf8 with vim

If you have several files that need to be converted to utf8, you can do it with vim.

First start vim with:

$ vim $(find . -type f -iname '*.htm*')

Which will find all .htm and .html files from the current directory.

Then in vim, use : to go into command mode.

Run these two commands:
:set nomore
:bufdo set fileencoding=utf8 | w

Reference:
https://stackoverflow.com/questions/4544669/batch-convert-latin-1-files-to-utf-8-using-iconv

Use Curl to read your imap emails

You can use the bash command “curl” to read your imap emails like this:

curl --url "imaps://imapserver.somewhere.net" --user "username:password"

Note: your password will be visible on the command line, so don’t use this on a public server.

So it is actually better to create a file, for instance called secret, then write your password in it, and protect it with:

chmod 400 secret

Then you can use this command instead:

curl --url 'imaps://imapserver.somewhere.net' --user 'username:`cat secret`'

If there is a SSL certificate issue, you can also try (not recommended of course):
[code lang=”bash”]curl –insecure –url "imaps://imapserver.somewhere.net" –user "username:password"[/code]
You need a newer version of curl, because version before 7.29 have limited imap support.

In order to upgrade curl on a Centos system, you can:

Create a new file /etc/yum.repos.d/city-fan.repo

Then paste the following contents:

[CityFan]
name=City Fan Repo
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch/
enabled=1
gpgcheck=0

Finally

yum update curl

You can very finally the version of curl:

curl --version

See also:

https://debian-administration.org/article/726/Performing_IMAP_queries_via_curl