GoDaddy Remove php Extension
- Article
- Comment (9)
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` .
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]
This does not work for godaddy
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.
Thanks, it works properly.
hi i want the code peramiter pass veriable with value and i want clean url with hide .php extention . plz sand the code who work in godaddy.
I think my code will work on url parameters. Try to use it like the url without parsing the extensions of a file.
tanks man finally i got wroking thanks a lot using go daddy
Welcome, I am glad to help you.
How should this look with only using https and no www?
Thanks!
It should work. additionally you have to redirect to https with 301 redirect