I am trying to set up Apache to use mod_rewrite and mod_dbd with postgreSQL for a club website. (Kubuntu 18.04, Apache 2.4, PHP 7.2) I can find some details for mod_dbd with mySQL, but I am having a very hard time with this combination. Any hints, suggestions or answers appreciated.

My current VirtualHost config file:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com

    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/html/example.com

    ErrorLog ${APACHE_LOG_DIR}/example.com/error.log
    CustomLog ${APACHE_LOG_DIR}/example.com/access.log combined

    RewriteEngine On
    RewriteMap  myquery    "dbd:SELECT page_name FROM page WHERE page_identifier = (%s)"
    RewriteMap  revquery   "dbd:SELECT page_identifier FROM page WHERE page_name = (%s)"

    RewriteRule ^/([A-Za-z0-9_-]+)$ /index.php?id=${revquery:$1} [L]

    RewriteCond %{QUERY_STRING}          id=(\d+)
    RewriteRule ^/index\.php?         /${myquery:%1}?    [R=307,L]

I have moved the following into the main config file and added a few more default statements. (And removed the <IfModule> tags)

DBDriver  pgsql
DBDParams "hostaddr= port=5436 dbname=page user=user password=pass"
DBDMin      1
DBDKeep     2
DBDMax     10
DBDExptime 60


Edit 4: - removed a lot of details regarding missteps - I was originally missing RewriteEngine On - I also had the RewriteMap statement wrong. The parameter apparently needs to be %s, although I am not sure exactly what that means - I found out that the <IfModule> tags were not necessary and I removed them. I probably want an error if those modules are missing!

Edit 5: it's now working!! Details changed above.

Meta question: Should I revert the question to an earlier form and move some of this info to an answer, or just leave it like this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.