ElkArte Community

Project Support => General ElkArte discussions => Topic started by: badmonkey on August 27, 2022, 01:15:55 am

Title: URL rewrite
Post by: badmonkey on August 27, 2022, 01:15:55 am
Hey gang! Hope everyone is well!!

Let's begin this question with a flashback. Once upon a time one of my sites was served by apache. The URL was modified such that "index.php" was replaced by a name, specifically "content". Therefore the URL in the address bar appeared like this:

www.example.com/content?topic=139248.msg1369386#msg1369386

This required the query string file in the sources directory to be slightly modified. It also required a rewrite placed into the apache vhost file. 

Fast forward a few years and a switch to nginx has come to pass. While nginx has served well, it seems to be falling behind the times. Perhaps test driving another is due. In this case I'd like trying openlitespeed, for several reasons.

Yeah, nginx may be right back. But that's another conversation altogether - we'll see how it goes - test drives are about discovery after all. 

Anyway, the years have resulted in losing the old apache vhost backup file with the proper rewrite/redirect/whatever the heck I did to it. Can anyone help provide code to drop into the OLS interface, or manually into the htaccess file to make the magic work again? Many thanks for reading!
Title: Re: URL rewrite
Post by: ahrasis on August 27, 2022, 02:09:22 am
That should be straightforward and google should be able to help you. I am still using nginx though.
Title: Re: URL rewrite
Post by: tino on August 27, 2022, 01:24:48 pm
https://www.301-redirect.online/htaccess-rewrite-generator

That should help you, you want the internal rewrite option so it’s transparent to everything.
Title: Re: URL rewrite
Post by: Spuds on August 27, 2022, 06:22:56 pm
I took a quick look but could not find my old apache setup ... been on nginx for so long!  I'll do some more looking around.

Be very interested in what you discover in your testing/playing with openlitespeed goes.  Are you seeing performance or memory issues with nginx or are there missing / to many features these days. 

My sites run a custom compile for pagespeed and ip location.  I then lock them down so apt can not update them, not even sure what version I' locked on right now .... OK had to look, its 1.19.7
Title: Re: URL rewrite
Post by: badmonkey on August 27, 2022, 08:21:01 pm
I think I have it sorted guys. Thanks for all the pointers! It's currently dinner time, so a there will be a follow up with the answer should it help anyone else.


@Spuds it is just what you said: features. Specifically it surrounds http3 though others count as well. Sure, they're planning to implement it "soon". "Soon" has been well over a year now. Nginx laid blame on openssl. They are indeed sluggish. Perhaps it's time they consider cutting bait to remain modern? I'm not hating, however. I'll give this a spin, assess the pros and cons, then continue with the winner!
Title: Re: URL rewrite
Post by: Spuds on August 27, 2022, 09:02:23 pm
Looks like "soon" maybe by the end of the year per their blog, as in no promises.  Let us know what you find out, a quick look at benchmarks show openLS beats Nginx (with some addon to properly support http3).  

I've become a bit of a admin panel stooge so unless ispconfig directly supports it, then I would not use it.  Yes I'm lazy these days, but it could be fun on my dev server/nas :D
Title: Re: URL rewrite
Post by: badmonkey on August 27, 2022, 11:53:18 pm
Here's the coding solution for anyone who needs a similar rewrite. This is the htaccess in current use:


Code: [Select]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^content/?$ index.php [L,QSA]


The first line should be obvious. The next few lines address file and directory access. After that we have a couple lines redirecting http to https. Last is not least here! The meat of the question centers around it. Essentially it gives index.php an alias within the address bar. Rename accordingly!
Title: Re: URL rewrite
Post by: badmonkey on August 28, 2022, 12:40:52 pm
Here's the skinny on OLS thus far. Configuration has truly been a headache. Online tutorials make it look simple enough. The problem is they omit critical steps. Like massive steps. The documentation is kind of ok in that they tell you what everything does, but they don't tell you how the ***hello*** to do it or why. Performance seems decent though certainly no better than nginx/fpm.

The last statement lacks any actual scientific data. It is based solely on perceived performance. Let's be honest here, there's no truly scientific means to benchmark two situations on a production server as the conditions will never be the same twice. Benchmarks on non-production servers are also questionable, as they fail to emulate what happens in the real world, i.e. a production server. So there's that. ;D

Anyway.....I think everything is operational sans attached images. Attachments upload properly. The download link and info display properly. But no image. Switching back to nginx/fpm and cache clearing results in functional attached images. Avatars and other images work fine. I'm not sure if it's a mime type issue, a missing header issue, or something else. @Spuds what mime type should it be, and what headers should be associated with attached images? Or should I look at something else??
Title: Re: URL rewrite
Post by: Spuds on August 28, 2022, 12:58:43 pm
The forum images should be sent with a contentType of image/xyz where xyz is gif jpeg png etc
If its a file then it would have a contentType of application/octet-stream

pretty standard stuff ... I'd open up your dev tools / network and look at one of the image requests and see what the server is sending back.
Title: Re: URL rewrite
Post by: badmonkey on August 28, 2022, 01:08:23 pm
Quote from: Spuds – The forum images should be sent with a contentType of image/xyz where xyz is gif jpeg png etc
If its a file then it would have a contentType of application/octet-stream

pretty standard stuff ... I'd open up your dev tools / network and look at one of the image requests and see what the server is sending back.
Thanks Spuds. That's what I thought. Everything appears in order there. I'm puzzled.  FF says the "image cannot be displayed because it contains errors". 
Title: Re: URL rewrite
Post by: Spuds on August 28, 2022, 02:07:48 pm
I feel that error is just a generic one that Fx will show for a variety of reasons.  
The response header for this site, to an image request, looks like this.
Code: [Select]
Accept-Ranges  bytes
Connection keep-alive
Content-Length 2448
Content-Type image/webp
Date Sun, 28 Aug 2022 17:56:13 GMT
ETag "62f70722-990"
Last-Modified Sat, 13 Aug 2022 02:06:26 GMT
Server nginx/1.18.0 (Ubuntu)
Strict-Transport-Security max-age=0
Not sure if you would need to clear your cache, always worth a shot.  I'd also start with a clear htaccess file just in case.
Title: Re: URL rewrite
Post by: badmonkey on August 28, 2022, 02:25:03 pm
Quote from: Spuds – I feel that error is just a generic one that Fx will show for a variety of reasons. 
The response header for this site, to an image request, looks like this.
Code: [Select]
Accept-Ranges  bytes
Connection keep-alive
Content-Length 2448
Content-Type image/webp
Date Sun, 28 Aug 2022 17:56:13 GMT
ETag "62f70722-990"
Last-Modified Sat, 13 Aug 2022 02:06:26 GMT
Server nginx/1.18.0 (Ubuntu)
Strict-Transport-Security max-age=0
Not sure if you would need to clear your cache, always worth a shot.  I'd also start with a clear htaccess file just in case.
Here's a different question. Imagemagick can't be installed with lsphp at the moment due to dependency issues. It's unclear if it's on the part of Imagemagick or OLS. Anyway, images should still work with gd, yes?
Title: Re: URL rewrite
Post by: Spuds on August 28, 2022, 04:26:17 pm
Yes GD is fine.

If you depend on the auto rotation functions then you need to make sure exif is installed as well, GD will need that.
Title: Re: URL rewrite
Post by: badmonkey on August 30, 2022, 10:59:47 am
Here's the latest update from the salt mines. OLS has effectively been abandoned. It's probably a simple configuration issue but I cannot get attached images working. Giggle provides little info on the matter. 

To make things worse, I attempted to register on the OLS support forums. Apparently Gmail rejects any correspondence from them even in the spam box! Soooo..... it's a sign. Inability to get support in any fashion= uninstall. Oh well. Nginx is a solid performer. Hopefully they'll intro http3 sometime in next decade. 
Title: Re: URL rewrite
Post by: Spuds on August 31, 2022, 12:13:56 pm
Thanks for the update!  That image thing is really odd.
Title: Re: URL rewrite
Post by: badmonkey on January 31, 2023, 09:38:39 pm
Quote from: Spuds – Thanks for the update!  That image thing is really odd.
The hound dog is digging these bones up again. We're drifting away from the original subject line as well, though there may be things learned  through the process. Turns out I stumbled across this:

https://www.simplemachines.org/community/index.php?topic=581559.0

I know, I know. Boo hiss on the location. Nonetheless it could be a clue if not an answer to the former debacle. http3 in absentia through nginx may warrant another trial run.

I do not use the Compressed Output function in the ACP, but it was enabled in OLS. Makes one wonder....

Anyone have thoughts???
Title: Re: URL rewrite
Post by: Steeley on January 31, 2023, 10:09:57 pm

After reading the link... "Incompatibility is just an upgrade away"  🙏

Yea, decompress..
Title: Re: URL rewrite
Post by: badmonkey on January 31, 2023, 10:59:50 pm
Quote from: Steeley –
Quote from: badmonkey –
Anyone have thoughts???

After reading the link... "Incompatibility is just an upgrade away"  🙏

Yea, decompress..
Indeed it is. Let's not mention Murphy. 
Title: Re: URL rewrite
Post by: Spuds on February 01, 2023, 12:18:09 pm
Quote from: Steeley – "Incompatibility is just an upgrade away
:thumbsup:  remember that when 1.1.9 comes out  :embarrassed:

If you want to give lightspeed another go, try it with 1.1.9 which did make some changes to the compressed output logic.  Specifically
- It sets the compression header when required (it does not rely on ob_clear  doing that (it was one of the php 8 bugs 1.1.9 addresses)
- It does not use compression if the file is an image or a mime type that does not warrant using compression (actually this had been this way from the start)
- It checks if the client is requesting or supports compressed output
- Sets a proper content length header
Title: Re: URL rewrite
Post by: Steeley on February 02, 2023, 09:37:51 am
Quote from: badmonkey –
Quote from: Steeley –
After reading the link... "Incompatibility is just an upgrade away"  🙏

Yea, decompress..
Indeed it is. Let's not mention Murphy.

I don't mind Murphy too much, he's just a passive observer. It's the 'phucque-up fairy" that that drops by unannounced and hangs around for a week or so and turns everything to  💩  that I can do without. That critter is evil.  :zipper_mouth:  
Title: Re: URL rewrite
Post by: Spuds on February 02, 2023, 11:20:23 am
So now I know why 1.1.9 is taking so long ... that little :fairy: keeps visiting  :shocked:
Title: Re: URL rewrite
Post by: Steeley on February 02, 2023, 01:32:49 pm
A day in the life of a visit... you wake up with a headache and a stiff neck, get out of bed and open the bedroom door, it catches on your left foot and stops half-way open, and you bust your nose on the edge of the door. The coffee machine quits and begins to smoke after brewing a quarter cup of coffee. The battery is dead in the car , you push it back and maneuver the wife's car across the lawn so you can jump-start it. You get a flat half way to work and discover the spare is also flat, and realize you left your cell-phone on the charger at home. A half hour later you flag down a passing tow-truck. When you finally do get to work you can't find your badge to get in the door.  You finally get in when someone comes out. You get to your workstation and get a message that you have to change your password, and your first 8 attempts are rejected because you've used them in the past two years already. In frustration you make something up, get in, and realize you're not sure now what you made up. Never mind, you'll deal with that later, and try to access your code files on a network drive, and.. it wants your new password. OK, so you'll deal with that now.  Finally the IT department gets you access, and you get to work..
You load up the source code you compiled yesterday, and proceed to "clean it up", removing comments you'd entered to aid in debugging. Now the source code won't compile. You put all the comments back, and it still won't compile.
So you load up the source file you compiled yesterday before going home, and it won't compile now either. You decide to get a cup of coffee in the break room and try to figure out what's going on. The new HR assistant comes in and brews a cup of hibiscus tea. Since you're allergic to hibiscus, you sneeze, and your nose explodes.
Yep, looks like the f'up fairy is back... 😰

Since the day is obviously going to be a waste anyway, you decide to burn some vacation hours, log out, and..... the car won't start.  No cell phone, no badge to get back in to use the work phone to call AAA for a jump... while you wait for someone to come out again, a tune starts running in your head..

https://youtu.be/aF4IkpZMuRk
 
o/ that f'up fairy won't let me be, poor poor pitiful me.. o/

Need more cowbell.. {sigh}
Title: Re: URL rewrite
Post by: Spuds on February 03, 2023, 10:02:50 am
I got a fever !
and the only prescription
is more cowbell :bell: