DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD Packages and Ports

OpenBSD Packages and Ports Installation and upgrading of packages and ports on OpenBSD.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 22nd January 2021
billy_bazooka billy_bazooka is offline
Port Guard
 
Join Date: Sep 2016
Posts: 28
Default (solved) how to remove ".php" from urls in httpd?

Is there a way to setup httpd to "rewrite" urls so that user can type "mywebsite.com/register" instead of "mywebsite.com/register.php"?

In lighttpd I do it like this:
Code:
url.rewrite-once = ( "^(.*)/$" => "$1/" )
url.rewrite-if-not-file = ( "^([^?]*)(\?.*)?$" => "$1.php$2" )
Is such a thing possible in httpd?

Last edited by billy_bazooka; 23rd January 2021 at 06:59 AM. Reason: marked as solved
Reply With Quote
  #2   (View Single Post)  
Old 22nd January 2021
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,188
Default

I have not tested this myself, but when request rewrite was added to httpd.conf(5) / httpd(8), this was proposed as the solution:
Code:
    location match "/page/(%d+)/.*" {
        request rewrite "/static/index.php?id=%1"
     }
Source: https://marc.info/?l=openbsd-tech&m=152763061916519&w=2
Reply With Quote
  #3   (View Single Post)  
Old 23rd January 2021
billy_bazooka billy_bazooka is offline
Port Guard
 
Join Date: Sep 2016
Posts: 28
Default

Quote:
Originally Posted by jggimi View Post
I have not tested this myself, but when request rewrite was added to httpd.conf(5) / httpd(8), this was proposed as the solution:
Code:
    location match "/page/(%d+)/.*" {
        request rewrite "/static/index.php?id=%1"
     }
Source: https://marc.info/?l=openbsd-tech&m=152763061916519&w=2
Thank you. It worked great.
Code:
location "*.php" {
  fastcgi socket "/run/php-fpm.sock"
}
location match "/(%a+)" {
  request rewrite "/%1.php"
}
As usual, everything was in the manpages.
Code:
man patterns
what a great friggin os!
Reply With Quote
  #4   (View Single Post)  
Old 23rd January 2021
billy_bazooka billy_bazooka is offline
Port Guard
 
Join Date: Sep 2016
Posts: 28
Default

actually, more correct is
Code:
location match "/(%w+)$" {
  request rewrite "/%1.php"
}
without $ at the end, it was matching images and other assets.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between"arp info overwritten" and " duplicate IP address " varag OpenBSD Security 1 6th April 2015 02:57 PM
How to replace "ectags" with "ctags"? fender0107401 OpenBSD Packages and Ports 5 16th April 2013 10:01 AM
Fixed "xinit" after _7 _8, "how" here in case anyones' "X" breaks... using "nvidia" jb_daefo Guides 0 5th October 2009 09:31 PM
"Thanks" and "Edit Tags". diw Feedback and Suggestions 2 29th March 2009 12:06 AM
can't start apache "httpd not running" disappearedng FreeBSD General 5 22nd September 2008 10:18 PM


All times are GMT. The time now is 01:27 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick