httpd icon indicating copy to clipboard operation
httpd copied to clipboard

Using rewrite for OctoberCMS

Open marianielias opened this issue 7 years ago • 3 comments

Hi, I'm trying to adapt the rewrite rules of OctoberCMS to httpd.conf. Now everything is working ok with this rules:

#example of directory that doesn't need to use rewrite.
location match "/themes/(.*)/assets/(.*)" {
request no rewrite
}

#index.php is the entry point of the application and runs the php fastcgi.
location match "index.php" {
fastcgi socket "/run/php-fpm.sock"
}

#all others locations rewrite to /index.php
location match "(.*)" {
request rewrite "/index.php$REQUEST_URI"
}

The problem is that when rewriting to index.php in this manner the links are formatted in the same way as the rewrite, is there a way apart from "request strip" that I can use to change the $REQUEST_URI so the fastcgi socket gets the value with the "/index.php" striped ? Or even better: a way to keep the original $REQUEST_URI ?

Cheers.

marianielias avatar Jul 26 '18 16:07 marianielias

Did you have any advancement in this?

I'm currently looking into doing the same for WordPress and would think the capture index (%1, %2, etc) would be usable to craft your own URL rewrites without the index.php:

     block [return code [uri]]
             Close the connection and send an error page.  If the optional
             return code is not specified, httpd(8) denies access with a `403
             Forbidden' response.  The optional uri argument can be used with
             return codes in the 3xx range to send a `Location:' header for
             redirection to a specified URI.

             It is possible to rewrite the request to redirect it to a
             different external location.  The uri may contain predefined
             macros that will be expanded at runtime:

                   $DOCUMENT_URI  The request path.
                   $QUERY_STRING  The URL encoded query string of the request.
                   $REMOTE_ADDR   The IP address of the connected client.
                   $REMOTE_PORT   The TCP source port of the connected client.
                   $REMOTE_USER   The remote user for HTTP authentication.
                   $REQUEST_URI   The request path and optional query string.
                   $SERVER_ADDR   The configured IP address of the server.
                   $SERVER_PORT   The configured TCP port of the server.
                   $SERVER_NAME   The name of the server.
                   $HTTP_HOST     The host from the HTTP Host header.
                   %n             The capture index n of a string that was
                                  captured by the enclosing location match
                                  option.

That's from the block docs in man httpd.conf, but rewrite says to use the same macros

leonstafford avatar Nov 07 '18 11:11 leonstafford

@leonstafford No advancement. I'm currently hosting my sites in a hosting provider so I'm not following the subject. Maybe the functionality that I'm asking for is just not implemented in httpd. Cheers.

marianielias avatar Nov 07 '18 15:11 marianielias

That was my concern, also.

I’ve posted here and will follow up with the responses soon:

https://www.reddit.com/r/openbsd/comments/9uyxmf/help_bringing_across_nginx_rewrite_rules_for/

On Wed, Nov 7, 2018 at 22:36 Elias M. Mariani [email protected] wrote:

@leonstafford https://github.com/leonstafford No advancement. I'm currently hosting my sites in a hosting provider so I'm not following the subject. Maybe the functionality that I'm asking for is just not implemented in httpd. Cheers.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/reyk/httpd/issues/79#issuecomment-436665330, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-JkXZZGDL7ujoprpaHxBipAwo5PzNCks5usv4agaJpZM4ViHrf .

leonstafford avatar Nov 07 '18 15:11 leonstafford