FreeKB - HTTPD hide .php extension
HTTPD - hide .php extension

By default, the .php extension will show in a web browsers address bar. For example, if you've a page named About.php, the address bar will show


Ensure the rewrite module is enabled. If rewrite_module is in the list of modules of the following command, then the rewrite_module is enabled.

[root@server1 ~]# httpd -M
. . .
rewrite_module (shared)


In the /etc/httpd/conf/httpd.conf file, inside of <Directory /var/www>, ensure AllowOverride is set to All.

<Directory /var/www>
. . .
AllowOverride All


The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to restart httpd.

systemctl restart httpd


If your system is using init, use the service command to restart httpd.

service httpd restart


Use the apachectl configtest command can be used to verify the configuaration of HTTPD is OK.

[root@server1 ~]# apachectl configtest
. . .
Syntax OK


Create the .htaccess file.

[root@server1 ~]# touch /var/www/html/.htaccess


Edit the .htaccess file, and add the following.

RewriteEngine On
RewriteRule ^about$ about.php [NC]


Now, .php will no longer be displayed.


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter a77bc in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |