Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HHVM - Rewrite rules for clean URLS

I have links like this - http://example.com/index.php?q=about and I want to make them look like this - http://example.com/about

Currently I am using the Rewrite Rules

VirtualHost {
  * {
    Pattern = .*
    RewriteRules {
      dirindex {
        pattern = (.*)/$
        to = index.php/$1
        qsa = true
      }
    }
  }
}

If I visit http://example.com/about I am getting a 404 File Not Found

I am doing this for Drupal. Guidelines for clean urls : https://drupal.org/getting-started/clean-urls

like image 308
Gokul N K Avatar asked Feb 17 '14 06:02

Gokul N K


1 Answers

The issue can be resolved using the VirtualHost, but the server module of HHVM is depreciated now, and you are encouraged to use fastcgi over apache/nginx. I will put an answer for VirtualHost, but if needed, can update with an nginx alternative.

First, make sure that your SourceRoot is correct:

Server {
  Port = 9000
  SourceRoot = /home/myuser/www
  DefaultDocument = index.php
}

Now, for the rule, this should potentially work:

VirtualHost {
  * {
    Pattern = .*
    RewriteRules {
      * {
        pattern = (.*)$
        to = index.php/$1
        qsa = true
      }
    }
  }
}

If you want the query to work exactly as you are intending it to, replace the inner pattern with this:

* {
pattern = /(.*)
to = index.php?q=$1
qsa = true
}

I have tested these both, and they work well. If you are still facing an issue, the issue may be potentially with your setup. Make sure you enable Error and Access logging .

like image 109
Sina Avatar answered Nov 24 '22 11:11

Sina