[Guide] htaccess remove PHP not working

In this article, you going through each and every point regarding htaccess file, and how to remove PHP in a step by step.

Let’s start with the discussion regarding htaccess remove PHP

Before moving toward the main topic first we will discuss main points regarding htaccess.

About .htaccess file :

Apache Web Server is a software for running the web servers with the help of a configuration file.

This file is called .htaccess file which is very important.

The Apache Web Server load .htaccess file which is a place in the directory.

It is the Apache Web Server software that is detected and then executes the .htaccess file.

To do any changes in the configuration of software called Apache Web Servers.

Such as enabling and disabling the functionality.

Many other features which is exist is to be done with the help of .htaccess files.

Using this file we can achieve many more things.

It includes facilities such as the functionality of redirect and also includes the error of 404 when a file is not found.

It also includes password protection and prevention for images hotlink.

Process of Using this .htaccess file

File ".htaccess" is a full filename, not the file extension.

The file .htaccess means simply the .htaccess file, no one creates a file.htaccess

The main working process of loading this file is to start.

When it is placed in the directory which is done by software.

The software is called Apache Web Server.

The main effect of this file is on all files.

This file is present in the specified directory and sub directories.

Below is the example you include in .htaccess file are as follows as.

AuthName "Member's Area Name"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html

There are many more examples that are advanced.

The protection of the password is enabled or disable on directory done with the help of this.

It is also useful for redirection to the error page.

When the user gets not login successfully, it helps to redirect to a custom error page.

It helps in enabling SSI – Server Side Includes which is useful for ‘.html’ files

After creating of '.htaccess' the file looks similar as above you have to upload this.

It is to be done using FTP.

You can download an FTP program from the given link: DOWNLOAD

Using the above link you can download and upload .htaccess file

.htaccess file should be in ASCII mode while uploading.

It is very important regarding in ASCII mode.

There are two different methods of transferring data.

Two methods are ASCII and BINARY.

It is very important that the file should be in ASCII, not in BINARY

Remove .php extension : htaccess remove PHP

To remove .php extension, you have to internally request each and every document.

For example, techone.in/sample.php replace by techone.in/sample.
To achieve rewriting techone.in/sample, use the below code in .htaccess file

This will completely remove .php extension from your file and also avoid occurring of infinite loop

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

Above script is only work if htaccess file is in the root directory i.e. ROOT/.htaccess

It is also very important to be sure in making changes to Rewrite Base if you place .htaccess in sub directory.

If Apache is 2.4 or later, for that use END flag to prevent occurring of infinite loop error.

Below is the example works if the Apache is 2.4 or above.

RewriteEngine on

RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]

if you want to remove .php extension specific file, then you can use the below code.

RewriteRule ^about$ about.php [L]

Create a custom error document

It is very useful in creating error pages which is totally custom.

With the help of this, you can show a visitor-friendly error message.

It is useful when a specific URL of the web site does not work in some instances.

With the help of a custom error page, you can show a friendly error message.

Instead of ‘404 File Not Found’ error message.

Friendly error message using you can provide the user with proper solutions.

So that users go back to web site content, instead of leaving the user in a frustrating condition.

For set-upping and using error document, create file called .htaccess file.

Below is the instruction given .htaccess document.

ErrorDocument 404 /error_pages/404.html

In the above snippet Apache Web Server tells document to be display which is located at /error_pages/404.html path.

It is occurs whenever at instance URL not found of you web site.

Form the above example, we consider that you have created an error document which is called '404.html' file.

This html file is placed in directory known as ‘error_pages’ which is inside your domain name.

Example are as follow as:


The file 404.html is basic simple HTML file.

This HTML file is similar like other HTML file which is used.

In this we used to display error messages of file not found.

For set-upping other error document.

Error such as ‘401 Unauthorized’, ‘500 Internal Server’ and ‘403 Forbidden’.

To do this create .htaccess file with following instruction.

ErrorDocument 401 /error_pages/401.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html

So finally we done with displaying of friendly error message with help of creating error document.

Redirects htaccess

With the help of redirect, you redirect to visitor from one document of your website to other document of your website.

This is helpful when you moved you website.

So at that time you can redirect your visitor from old link to new location.

For set upping redirect, create .htaccess file with following instruction are as follow as:

Redirect /old_dir/ http://www.yourdomain.com/new_dir/index.html

With the help of above code Apache Web Server come to know and it has to redirect from old link to new link.

In the above code snippet example, there is an old directory which is the place of the document which is get requested from the visitor.

It can be document also or a directory also which is inside your main domain.

In the above example, the 'old_dir'  directory is located at 'http://www.yourdomain.com/old_dir/'.

From above example you also come to know that the full website URL represents where visitor to be redirected.

And from where the visitor is to be redirected is only given the folder directory.

This means that the above code snippet when we define in .htaccess file.

It will tell Apache Web Server to redirect the visitors from old directory to new directory the content of the website

So we finally done with the complete process of redirection.

I hope you liked my this article. If you have any queries or any question regarding this, Feel free to comment on Me.

Guide to Get Weekly Data In PHP

Leave a Comment