Post by Joe1234 » Tue Apr 09, 2024 7:23 am

The following is causing my few of my controllers to load twice...so far I've found it to be happening to my header and footer.

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Can someone explain what exactly this is doing, what it's for, if there is an alternative? I really don't know anything about htaccess, I just put stuff in that there seems to be a consensus that they are good practices or needed. The flip side of this piece of code is if I remove it I get a 404 error on everything except my home page. I have SEO rewrite on for SEO pages.
Thanks.
Last edited by Joe1234 on Wed Apr 10, 2024 2:10 pm, edited 1 time in total.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by nonnedelectari » Tue Apr 09, 2024 7:58 am

That code is essential for SEO urls.

in pseudo code:
if the requested url is not a file in your filesystem and
if the requested url is not a directory in your filesystem and
if the requested url does not end with .[any of the extensions listed] (i.e. static assets)
invoke index.php and pass along the entire url as _route_ variable and let OC handle the routing.

Without that code the webserver would initiate a 404 as the url does not physically exists which is the case with all SEO urls.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by nonnedelectari » Tue Apr 09, 2024 10:32 am

I read somewhere on this forum that it would be better to replace line 3 with:

Code: Select all

RewriteCond %{REQUEST_URI} !.*\.(cfg|ico|cur|mp3|webp|svg|ttf|eot|woff|woff2|gif|jpg|jpeg|png|js|css|pdf|zip|env|tar|sql|gz|tar|exe|rar|arj|cab|iso|rpm|tbz|tgz|old|bak|backup|dump|db|7z|asp|exp|json)$
as that would prevent scanner bots looking for those static assets on your server from also invoking index.php and execute your OC SEO url logic causing unnecessary processing which eventually would result in a 404 anyway.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by Joe1234 » Tue Apr 09, 2024 1:37 pm

1/ So in order to have seo url there is this downside to loading controllers/models twice which doubles the task on the server and database? That seems odd that a problem like that exists with no solution...and that I didn't find anything about this on google.

2/ Changing the 3rd line prevents the bots from looking? Or it prevents the bots from finding those other files?

Thanks.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by nonnedelectari » Tue Apr 09, 2024 3:50 pm

1) no, you asked for an explanation on what that code is for and what it does, that code has nothing to do with loading controllers twice.
2) no, it prevents scanner bots from initiating your SEO url logic when requesting urls with those extension when they do not physically exist, and virtually all of those do not physically exist on your server. Without the SEO logic, when a scanner bot requests /website-backup.zip, the webserver would issue a 404 as you have no file /website-backup.zip (hopefully) . With that SEO logic, index.php is initiated and your SEO url logic with the keyword database calls etc. eventually resulting in a 404 anyway as the keywords will not be found. So it is purely to prevent unnecessary code execution.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by Joe1234 » Wed Apr 10, 2024 2:08 pm

Looks like I found the secondary...or primary...issue. It seems I inadvertently deleted "RewriteBase /" and that seems to be the issue...at least with my site. I didn't have that and it was causing the duplicate loading of the header and footer (probably others as well that I didn't notice).

So if anyone else is having this issue and has SEO active. Make sure the RewriteBase stays in the htaccess, or remove what's in the OP...which will end up messing up navigating your site.

@nonnedelectari thanks for the info.

v3.0.4.0 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am
Who is online

Users browsing this forum: No registered users and 25 guests