rewrite snippets

How to improve your PageRank with 301 permanent redirects when using Nginx

Tagged seo, www, 301, permanent, nginx, redirect, rewrite, module  Languages 

Mathew Innman of fame wrote about how Digg could increase their revenue by using a so called canonical URL for their whole site. This can be implemented by redirecting users that type in, for example, to The reasoning being that instead of having backlinks pointing to two different domains (www and no-www), all backlinks should point to just one, which increases your search engine ranking.

if ($host ~* "www") {
      rewrite ^(.*)$$1 permanent;

Permanent redirects are also a good idea, if you move your content to a new to, for example...

The syntax for the Nginx rewrite module is documented here.

Configuring Apache to be a forward proxy

Tagged forward proxy, apache, forward, proxy, rewrite  Languages apacheconf

First enable the proxy and proxy_http modules:

sudo a2enmod proxy
sudo a2enmod proxy_http

Then use this configuration to make Apache act as an HTTP proxy:

<VirtualHost *:8080>
# Enable forward proxy
ProxyRequests On
# Add "Via" header
ProxyVia On
#ProxyRemote * http://...:8080 Uncomment to route requests through another proxy

<Proxy *>
    Order deny,allow
      Deny from all
  # Allow access only from local network
  Allow from 192.168.1
# Enable caching proxy
CacheRoot "/tmp"
CacheMaxExpire 24
CacheLastModifiedFactor 0.1
CacheDefaultExpire 1

ServerName my-proxy

ErrorLog "/var/log/apache2/proxy-error.log"
CustomLog "/var/log/apache2/proxy-access.log" common

Also read this.


You can use mod_rewrite to rewrite requests. To rewrite root (/) to /temporary_outage you could use the following rewrite:

RewriteCond %{HTTP_HOST} ^(www\.)?xxx\.com 
RewriteRule /$ http://%{HTTP_HOST}/temporary_outage/ [P,L]