Best place for rewrite rules to remove .php file extension

Keywords: LAMP/MAMP/WAMP - AWS - How to - Other
Description:
Hi,
thanks so much for creating the Bitnami HTTPS Configuration Tool. It was very helpful to me with redirecting my site to its www and https version.
Now, I also want to remove the .php file extension from all my pages to make the urls easier to read. My question is not about the necessary Apache syntax but simply about where to put it. I cannot locate any htaccess.conf file, should I create one? Or can I simply put it in one of the many configuration files already there, if yes, in which one exactly?

Thanks so much for your time and I hope this topic is interesting to other people as well.

Kind regards,
Matt

Hi @IAmGrateful,

Thanks for using Bitnami! Could you check this documentation about htaccess.conf https://docs.bitnami.com/aws/apps/wordpress/administration/use-htaccess/?

I hope that helps you.
Ibone.

1 Like

Hi Ibone,

thanks for your reply.

I had a look at what you referenced.
Since I’m not using any application like WordPress, there is no .htaccess file in my directory except for those of certain frameworks (codeigniter, laravel, etc.). The only two apps in my bitnami folder are “letsencrrypt” and “phpmyadmin”
This is also why the Bignami HTTPS Configuration Tool was so helpful to me as it automatically picks the right files to modify. After I had used it I discovered that it changes “/opt/bitnami/apache2/conf/bitnami/bitnami.conf”. So maybe that is the right file.

Creating a new htaccess.conf file might be another option. But then the question is where to best put it to maximize security.

Thank you very much and kind regards,
Matt

Hi @IAmGrateful,

Sorry this is the correct link https://docs.bitnami.com/oci/infrastructure/lamp/administration/use-htaccess/

1 Like

Hi Ibone,

unfortunately this doesn’t work for me.

I’m not using any app in that sense. What I have is a LAMP-stack from Amazon Lightsail without anything like WordPress. So there is no path “/opt/bitnami/apps/APPNAME/…”. The only apps I see are “letsencrypt” and “phpmyadmin”.

I managed to create some caching directives in “opt/bitnami/apache2/bitnami/httpd.conf”.
However, I can’t use this file for redirects or even to point to custom error pages. My changes with regards to this are ignored or overwritten.

Kind regards,

Matt

Hi @IAmGrateful,

Could you check this old thread of the community?

Here it’s the new link to disable PHP-FPM https://docs.bitnami.com/bch/infrastructure/lamp/administration/disable-phpfpm/

I hope that helps you,
Ibone.

1 Like

Hi Ibone,

thanks for referring me to this thread.

However, when disabling PHP-FPM I get an “503 Service Unavailable” error for my website.
It stays there for at least 30 minutes so I turned it back on.

Kindly,
Matt

But I’ll try again tonight.

The error persists. I’m following the instructions to disable PHP-FPM very carefully but as soon as I stop PHP-FPM my website becomes unreachable with a 503 error.

I’m not sure what’s easer: get Lightsail running without PHP-FPM (assuming this would already solve the issue) or configure Lightsail such that my rewrite rules concerning basic tasks like adding “.php” or defining a custom 404-page are respected.

Kindly,
Matt

Hi @IAmGrateful,

If there is a 503 error is because there is something wrong in the configuration. Did you check the content of the Apache’s log file to see what the error is?

https://docs.bitnami.com/aws/apps/wordpress/troubleshooting/debug-errors-apache/

Removing PHP-FPM shouldn’t add problems to the installation so there should be an error in the configuration as I mentioned above. Can you run the Bitnami Support tool again so we review everything again?

1 Like

Hi jota,

thanks for joining in!

The error in the log reads as follows:
[Sun Oct 04 07:51:35.440652 2020] [proxy:error] [pid 28393:tid 140367776712448] (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /opt/bitnami/php/var/run/www.sock (www-fpm) failed
[Sun Oct 04 07:51:35.440713 2020] [proxy_fcgi:error] [pid 28393:tid 140367776712448] [client 64.252.86.86:27064] AH01079: failed to make connection to backend: httpd-UDS

I tried what seems to have worked here:


But for me, (re)starting the services didn’t help.

I ran the support tool and this is my code:
3014f349-6102-5e78-66a0-ee53dab94e3d

Kind regards,
Matt

Hi @IAmGrateful,

You disabled the PHP-FPM process but didn’t update the Apache’s configuration. I can see that the mpm_prefork_module and php7_module modules are not enabled and that’s why you get those errors.

https://docs.bitnami.com/bch/infrastructure/lamp/administration/disable-phpfpm/

Please update the Apache’s configuration and restart the service for the changes to take effect

1 Like

Hi jota,

I tried applying those changes both to “opt/bitnami/apache2/conf/httpd.conf” and “home/bitnami/stack/apache2/conf/httpd.conf” but to no avail.

Hi @IAmGrateful,

I think you forgot the first slash character in both paths. You need to use /opt/bitnami/apache2/conf/httpd.conf.

1 Like

I’m modifying the files with Cyberduck, so this should not be the issue.

I also tried resetting the cache of my Cloudfront instance, but without success.

Hi @IAmGrateful,

You should be able to edit those files with Cyberduck, what problem did you find? Remember that you will later need to access the instance and restart the service

sudo /opt/bitnami/ctlscript.sh restart apache
1 Like

Hi jota,

thanks for your patience.

I didn’t find any problem editing those files with Cyberduck. It’s just that while I omitted the first slash character in both paths in my previous post, that should not have been the issue since I actually wasn’t accessing the configuration files via command line.

I’ve successfully modified the server configuration of this instance using Cyberduck before.

Also, I’ve ensured to restart the service after any changes I made.

But still, I’m having this issue.

Hi @IAmGrateful,

Instead of using the configuration posted in that other thread, can you take a look at this SoF guide to know if that works for you?

https://stackoverflow.com/questions/10028025/how-can-i-use-htaccess-to-hide-php-url-extensions

1 Like

Hi jota,

thanks for this suggestion!

It works perfectly.

But is working with an .htaccess-file in the root directory not less safe than what you recommend in the official documentation?

Kind regards,

Matt

Hi @IAmGrateful,

As you are using LAMP, we set the “AllowOverride” to All so you can deploy your application in the htdocs folder without problems. You can modify that parameter in the /opt/bitnami/apache2/conf/bitnami/bitnami.conf and move the .htaccess information to that file as well. You will need to include new “Directory” blocks inside each VirtualHost. You can also create a new htaccess.conf file and “Include” that file in both VirtualHosts.

Happy to help!


Was my answer helpful? Click on :heart:

1 Like