SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Is it possible to remove this extension

    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.

  2. #2
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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...

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    51
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Or create .htaccess file in the root of your website and place this code inside:

    Code:
    RewriteEngine on
    RewriteRule ^([a-zA-Z0-9_-]+)$ $1.php [L]
    If you already have .htaccess file, just append this code to it.

    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.

  5. #5
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi, I am not familiar with .htaccess how to use this ?

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by jemz View Post
    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

    Code:
    Options -MultiViews +FollowSymlinks
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.+)$ $1.php
    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.
    Last edited by ScallioXTX; Apr 14, 2013 at 05:22. Reason: Use (.+) instead of (.*) in RewriteRule -- thanks DK
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  8. #8
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by jemz View Post
    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

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  10. #10
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  12. #12
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by dklynn View Post
    1. (.*) can be null which would redirect to .php - not a pretty picture. IMHO, always require something, i.e., + rather than *.
    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.

    Quote Originally Posted by dklynn View Post
    2. "Out of the box," .htaccess does work. It's mod_rewrite which, by default, does not work (must be enabled).
    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

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •