Hi, can i ask some help,is it possible to remove the extension php(.php) in the url ?
I want that the url looks like this it removes the .php extension in the contact.
can you help me please how to achieve on this
Thank you in advance.
| SitePoint Sponsor |




Hi, can i ask some help,is it possible to remove the extension php(.php) in the url ?
I want that the url looks like this it removes the .php extension in the contact.
can you help me please how to achieve on this
Thank you in advance.


create a folder called contact and rename your file to index.php
Do you get bothered because I do the same thing every day?
Do you question why I do it?
Then find something that you actually like doing!!!
Stop thinking on what I do.




I mean to my every page, i want to remove the .php extension
http://mysite.co.uk/contact
http://mysite.co.uk/view
http://mysite.co.uk/about
etc...
Or create .htaccess file in the root of your website and place this code inside:
If you already have .htaccess file, just append this code to it.Code:RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)$ $1.php [L]
This will basically rewrite everything to the same thing plus ".php" so if you request yourwebsite.com/contact it will open yourwebsite.com/contact.php
The regex in this code doesn't match dot (.) so ordinary files (with extension) shouldn't be rewritten, e.g. if you request yourwebsite.com/contact.css it will serve it correctly, it won't load yourwebsite.com/contact.css.php
Note: This is .htaccess rule for Apache server with mod_rewrite support. It may work on other servers that support similar type of URI rewriting.


then you need to do it either with a cms so everything is filtered through the index file or in the htaccess file something like
Code Csharp:RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^GET\ (.*)\.php\ HTTP RewriteRule (.*)\.php$ $1 [R=301]
please note I am not very good at redirects on the htaccess file so read more on that and or ask you question in a specific forum for that
Do you get bothered because I do the same thing every day?
Do you question why I do it?
Then find something that you actually like doing!!!
Stop thinking on what I do.




Hi, I am not familiar with .htaccess how to use this ?

A .htaccess file is a special file with instructions for the web server (apache).
You can tell it to do specific things like redirect certain requests.
For this instance the easiest way is to create a file called .htaccess and put the following in it
That will rewrite all requests that have a .php counterpart to that .php counterpart, i.e., /contact to /contact.php etc, but if and only if that .php file exists.Code:Options -MultiViews +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.+)$ $1.php
Last edited by ScallioXTX; Apr 14, 2013 at 05:22. Reason: Use (.+) instead of (.*) in RewriteRule -- thanks DK
Rémon - Hosting Advisor
Minimal Bookmarks Tree
My Google Chrome extension: browsing bookmarks made easy




HI ScallioXTX,
Thank you for the reply...Okay i will try this,what if i am working on the local do i need to configure my apatche?...
Thank you in advance.![]()

Out of the box .htaccess don't work on apache. To enable them, follow the instructions described under the header "Server Setup" on this page: http://datakoncepts.com/seo
Rémon - Hosting Advisor
Minimal Bookmarks Tree
My Google Chrome extension: browsing bookmarks made easy




Thank you so much for the reply, Okay i'll give a try on this, i will write back to you if i get in trouble. thank you.![]()

Rémon,
1. (.*) can be null which would redirect to .php - not a pretty picture. IMHO, always require something, i.e., + rather than *.
2. "Out of the box," .htaccess does work. It's mod_rewrite which, by default, does not work (must be enabled).
3. Thanks for the referral, anyway, as the SEO page should clear it all up for him!
Regards,
DK
David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
Updated mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator

Indeed, that's what the RewriteCond %{REQUEST_FILENAME}\.php -f is there for; to prevent invalid requests like the one you're proposing
That said, (.+) would indeed be better than (.*) in this case. I'll amend my earlier post.
Ah yes, you're right. It's been a while since I've set up an apache server from scratch and I tend to forget these things![]()
Rémon - Hosting Advisor
Minimal Bookmarks Tree
My Google Chrome extension: browsing bookmarks made easy
Bookmarks