1

I am running an httpd(8) web server on OpenBSD. php-8.1.9 is used to serve php. In /etc/httpd.conf I have the following (example.com is a placeholder for the actual domain):

server "example.com" {
    listen on * tls port 443

    tls {
        certificate "/etc/letsencrypt/live/example.com/fullchain.pem"
        key         "/etc/letsencrypt/live/example.com/privkey.pem"
    }

    root "/example.com/"
    directory index index.php

    location "*.php" {
        fastcgi socket "/run/php-fpm.sock"
    }

    location "/" {
        pass
    }

    location not found match "/(.*)$" {
        request rewrite "/%1.php"
    }
}

The last two location blocks are my attempt to rid URLS of their '.php' suffixes in order to make my site look more professional. They partially work as intended. That is, users can access both https://example.com/foo and https://example.com/foo.php.

This would not be a problem if I were manually writing HTML, because I could just use a hyperlink to redirect users to the https://example.com/foo version.

However, there is a problem because I am using a static site generator which generates a lot of pages. Each page contains HTML which redirects users to other pages ending in '.php'. I can't easily edit the generator, because it is a compiled C program. Besides, it would be far easier to just redirect sites ending in '.php' to their much cleaner and non-suffixed versions. Is there any way to do this with httpd?

The man page for httpd.conf gives an example of redirection using the block directive:

server "example.com" {
    listen on 10.0.0.1 port 80
    listen on 10.0.0.1 tls port 443
    block return 301 "$REQUEST_SCHEME://www.example.com$REQUEST_URI"
}

However, I am not familiar enough with httpd to know how to do this myself. Any help would be kindly appreciated.

0

You must log in to answer this question.

Browse other questions tagged .