Avoid php extension in url by htaccess file


To avoid php extension like (.php) in url add the code to handle error exception and remove .php from url.

Add this code in htaccess file located in your server.

Create error.html file in server folder directory   and   type the url to avoid php extension.

RewriteEngine On
#Error pagesErrorDocument 400 /pagenotfound/error.html
 ErrorDocument 401 /pagenotfound/error.html
 ErrorDocument 403 /pagenotfound/error.html
 ErrorDocument 404 /pagenotfound/error.html
 ErrorDocument 405 /pagenotfound/error.html
 ErrorDocument 410 /pagenotfound/error.html
 ErrorDocument 500 /pagenotfound/error.html
 ErrorDocument 501 /pagenotfound/error.html
rewritecond %{http_host} ^cop.globastechnologies.com [nc]
 rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
# Unless directory, remove trailing slash
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
 RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
 RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]

Resolve .php file for extensionless php urls

RewriteRule ^([^/.]+)$ $1.php [L]

Advertisements
About

myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , , , , , ,
Posted in htaccess

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow php tutorial on WordPress.com
categories
Calendar
October 2014
M T W T F S S
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  
Follow me on Twitter
Blog Stats
  • 75,924 hits
%d bloggers like this: