X

GoDaddy Remove php Extension


GoDaddy Remove php Extension is also similar with removing html extension, just quite similar way to do that one. There are some difference in writing `.htaccess` on godaddy hosting and other hosting service. Even apache has some different settings from each hosting service provider. Generally, Godaddy has some extra measures on coding.  Let’s see the `.htaccess` code to hide `.php, or, .html or .any extension` .

apache.htaccess-godaddy

You have to create a `.htaccess` on  your root of the domain directory.  This article will help you, if your hosting is shared or unlimited hosting. You have many domains within it. And you have many domains allocated on separate directory.  So, goto the directory, where your domain has pointing. and on the root of the domain directory. create your `.htaccess` file. Than we will write our code within it.

We should start with  multiviews, ortherwise your code won’t work on godaddy. Let’s look the code,.

Options -MultiViews

And you can begin writing your rewrite engine and rewrite base.

Options -MultiViews
RewriteEngine On
RewriteBase /

Now, we have to remove the .php or .html from the url  by using the `THE_REQUEST` and prevent the infinite loop by using the following code.

RewriteCond %{HTTP_HOST} ^www\.kvcodes\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

Here I used my website url, you can change it to your domain name here.  Than remove the index by redirecting it .

RewriteRule (.*)index$ $1 [R=301]

If the url ends with slash and if the url is not pointing a directory, than we should remove the slash, otherwise it will be parsed as directory and it will look the index.php. So we will use the below one to remove it.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

And we have to access .php file when the url has opened and it should not redirect to another place.

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

Finally, here is the complete code for you.

Options -MultiViews
RewriteEngine On
RewriteBase /

# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{HTTP_HOST} ^www\.kvcodes\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

# remove index
RewriteRule (.*)index$ $1 [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

3 comments

  1. commenter

    This does not work for godaddy

    • commenter

      I applied the same code on godaddy shared hosting and unlimited hosting. Both working fine for me. I did a lot of research to make it working. I am sure this is working well.

  2. commenter

    Thanks, it works properly.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Subscribe to our email newsletter.

 

Advertisement

Category Posts