Grow your CSS skills. Land your dream job.

Last updated on:

Remove File Extention from URLs

RewriteRule ^about$ about.php [L]

That little bit will make http://example.com/about.php be able to load at http://example.com/about

Comments

  1. Permalink to comment#

    The following may be considered over the top, but I like to take it one step further by adding a trailing slash. If the slash is missing I feel like something is left… unfinished? Just a personal quirk I guess.

    This rule will match site.com/path/ and check to see if site.com/path.php exists. If the file exists it proceeds with the rewrite.

    RewriteCond /%{REQUEST_FILENAME}.php -f
    RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php

  2. Dyllon
    Permalink to comment#

    This one seems a bit easier:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

    • This version breaks any urls with a dash ‘-‘ between words.

      Although that said Greg’s seems to as well…

    • Dyllon

      I’ve never encountered that problem. In fact, I just tried it and it worked fine.

    • Richard Ellis
      Permalink to comment#

      Having tried all the examples above,

      RewriteRule ^about$ about.php [L]
      &
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME}\.php -f
      RewriteRule ^(.*)$ $1.php

      I am unable to see any change to my site URL’s.

      The suffix is still visible when I reload the page.

      Any ideas on how I can correct this?

    • mod rewrite works only on apache server.
      before trying please be sure that you are working on apache server and the mod rewrite module/extension is enabled.

    • @Chris Radford
      Hello Chris Radford, there may be some server problem with you or you might not using apache.
      I have used the above code and it works well for my website.
      http://jayjalaramext.com/brass-section-profile opens http://jayjalaramext.com/brass-section-profile.php

    • Permalink to comment#

      Thanks
      that works nice

    • Samsun Nahar
      Permalink to comment#

      I am unable to see any change to my site URL’s. How can I changed that. When i visit I found every time .html extention. Please give me a easy solution for solve this… I am waiting for expert reply…. Thank You

    • Leo
      Permalink to comment#

      Thanks Dyllon.

    • Muhammad Zia ur rahman
      Permalink to comment#

      Dear Dyllon,

      You did not mention that how we will apply this code..! for this i will guide…
      we will make one file with the name of (.htaccess) and after that will paste this code.

      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME}.php -f
      RewriteRule ^(.*)$ $1.php

      and save it in the root of the site.

      and after that one by one we will change the link, eg. about_us.php to about_us and so on.
      keep enjoying the programming.
      Thanks.

  3. Permalink to comment#

    i would like this snippet, but how can use this snippet? where i use it? anyone explain this deeply?

    • BobbyJones

      put it in your .htaccess file in the directory where you want the changes to take affect

  4. elandy2009
    Permalink to comment#

    A simple thing: This rule is inserted in an Apache Server .htaccess file. If you don’t have this file, you must create it. And this requires your host has activated the rewrite module.

  5. Permalink to comment#

    Hi! I have a question about URL rewrite. I use a dynamical php file to load my posts as usual and I use the rewrite in the form: mydomain.com/id_title-of-the-post , so as you can guess, the real URL is something like mydomain.com/file.php?id=XX , and I look in my database for the post with id=XX.

    In that case, the only real thing that matters in the URL is the “id” part. You could type mydomain.com/id_another-stupid title-of-the-post, and you will get to the same post.

    But I’ve seen that, like in your website, your URLs are in the form css-tricks.com/category/title-of-the-post ….you don’t use an ID anywhere so the only thing I can think right now is that your DB query looks for the post where title field=title of the post.

    Am I right or i’m talking BS? I can make that query too but I thought that looking for just an ID is way much faster for the database.

    This is all under the assumption that you also use a dynamical file that loads your posts and each one is not an independent html file.

    I would really appreciate if you can shed me some light on that matter. Thank you very much! (I really like your web ^^). Greetings from Peru =]

  6. Permalink to comment#

    This is awesome, I had no idea you could do that. Will be doing it on my sites later on :)

  7. Jeff
    Permalink to comment#

    Dyllons method worked for me. Thanks for that, been looking around and no other method that I found worked for me.

  8. Boris

    Hello Chris and everyone.
    My first post here. Thank you for all the great tips! I’d like to share my favorite version of the script. It does not add a trailing slash unless you visit a index file. Remember to remove the “.php” from your href links.


    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

  9. joe
    Permalink to comment#

    Hi everyone

    A question. I use the trick and works perfect with files in the main root
    RewriteRule ^about$ about.php [L]
    my problem is with subdirectory files
    RewriteRule ^/path/about$ /path/about.php [L]
    can someone help me to use the trick?

  10. surendhiran
    Permalink to comment#

    Hi
    Remove File Extention from URLs is not working in my site.. Can you give some tips to solve the proble

  11. Simon
    Permalink to comment#

    What would the code be if it were to remove both .php and .html from the url?

  12. Michelle
    Permalink to comment#

    I just wanted to say that the comment “Remember to remove the “.php” from your href links.” was the magical ray of sunshine that got this to work for me! I hadn’t done this at first, but now this works wonderfully!

  13. Thanks and q's
    Permalink to comment#

    This original suggestion works well but means you need to list each page to have its extension removed, which may become quite tedious so I tried the one suggested by Doug which works and means it can be sitewide rather than specifying each page. The one suggested by Boris works too and have 1 less line of code so I am using that one.

    So, the questions is: Is there any way to combine this sitewide code with a 301 to automatically redirect all requests to their extensionless url???

    P.S. Really great site in general and loving the htaccess tips.

  14. Permalink to comment#

    @Richard Ellis: If your website’s extensions are anything other than “.php”, then you have to change the .”php” to “.html” in the code you copy.

  15. The code worked, but now it removed all my css when you go straight to http://www.whitebluffsbrewing.com/news – Any suggestions?

  16. Thanks ! That worked for me !!!!

  17. Boris
    Permalink to comment#

    Hello again.

    I’m sorry I gave that bad advise in the earlier post – to remove .php from href links. I was young and stupid.

    I have a better solution. I’ve decided to go a bit in details for those who need it. Take a look and read on.

    # Apache Rewrite Rules
     <IfModule mod_rewrite.c>
      Options +FollowSymLinks
      RewriteEngine On
      RewriteBase /
    
    # Add trailing slash to url
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
      RewriteRule ^(.*)$ $1/ [R=301,L]
    
    # Remove .php-extension from url
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME}\.php -f
      RewriteRule ^([^\.]+)/$ $1.php 
    
    # End of Apache Rewrite Rules
     </IfModule>
    

    Things I guess you want to know:

    1. This is for sites that don’t use a front-end-controller where all requests are forced through index.php. If you need that, you must replace the third block with your own.

    2. The example is showed with .php only. If you want to use it with .html for example, you must copy/paste the third block and replace “.php” on line (1,) 3 and 4 with “.html” (unless someone has a neat way of doing it?)

    3. The content of “http://example.com/something/” could be served from either “http://example.com/something.php” or “http://example.com/something/index.php”.

    4. To link to other pages, just href=”/some/thing/” or href=”http://example.com/some/thing/”.

    5. With .css and .js you want to href=”/style.css” or href=”/folder1/style.css”. Else if you href=”style.css” from “http://example.com/folder2/file.php” it’ll look at “http://example.com/folder2/style.css”.

    Boris

    • @Boris: I’m using your solution on my site, and I find that it works great for one level. Thanks very much! But how do I use it for a site with multiple levels? If I set up example.com/contact.html, then example.com/contact/ will go to that page. But if I create a directory called contact/ and try to add contact/thanks.html (I want to have example.com/contact/thanks/), then going to example.com/contact only gives me the listing of the contact directory instead of contact.html. How do I fix this? (Or is a different hierarchy better?)

    • David Joyce
      Permalink to comment#

      This works really well to add the trailing slash back in, but what if you want to put some variables in your URL? So for example, if I wanted example.com/something/variable_for_something_template where something is actually “something.php” and variable_for_something_template is a value that the something.php template looks for?

  18. Thanks, Boris. Your solution worked perfectly for me! :)

  19. Permalink to comment#

    Hi All,

    I’ve been trying to remove the .html file extension from my site.

    I’ve uploaded a .htaccess file to my root directory, with this:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^([^/]+)/$ $1.html

    Nothing is happening.

    I previously tried this:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html

    As well, and got an internal server error on all of my pages.

    Any help would be greatly appreciated…the above comments mostly had to do with removing .php so I didn’t know if those would apply.

    Thank you!

    • Permalink to comment#

      Looks like you got it working, perhaps without knowing. I went to your site and the pages loaded with the .html extension, but when I removed the .html, it loaded the same page.

      These rewrite rules don’t mean the page won’t stop loading under the old name, but it just makes the other name work as well. I imagine there is a way to redirect the .html to remove the extension, but I’m not sure how and I imagine there is some fancy trick to it.

      Hope I helped.

  20. leandro
    Permalink to comment#

    change the permission in your file manager on server to “644” or “777” maybe work

  21. Jeff
    Permalink to comment#

    Hey great post and interesting topic. Thanks for sharing.
    I found Boris’ last submission to be the best option.

  22. sheriffderek
    Permalink to comment#

    Anyone tried this while using ajax to inject the main content ? wondering if that has something to do with my lack of success… ?

  23. Permalink to comment#

    i tried this in .htaccess file but its not working can you please check this

  24. Permalink to comment#

    i have rewrite my forum .php into .html like this ;
    RewriteEngine On
    RewriteBase /forum
    RewriteRule ^(.*)_([0-9]+).html$ index.php?id=$2 [L]
    RewriteRule ^(.*)_([0-9]+)_p([0-9]+).html$ index.php?id=$2&page=$3 [L]
    RewriteRule ^(.*)_p([0-9]+).html$ index.php?act=post&id=$2 [L]
    RewriteRule ^(.*)_([0-9]+)_s([0-9]+).html$ index.php?id=$2&start=$3 [L]
    RewriteRule ^(.*)_([0-9]+)_clip_p([0-9]+).html$ index.php?id=$2&clip&page=$3 [L]

    anyone can help me to remove .html etension?? please,,,

  25. soe
    Permalink to comment#

    Hi All,
    I’m trying to rewrite http://www.example.com/services.php?m=services&s=scan book&id=2 to http://www.example.com/services/services/scan-book/2 . I tried many ways and also tested above examples. But it is not ok yet. I encountered the following error.
    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator, webmaster@example.com and so on ….
    Can any body help me solve my problem please?

    Many Thanks

  26. kumar
    Permalink to comment#

    Hi All,
    I am trying to rewrite the URL http://www.example.com.br/folder/sub_folder/my_profile.php to
    http://www.example.com.br/folder/my-profile. I have tried lot of rewrite method but i can’t redirect the URL.

    Please anyone help to solve this.

  27. Rojin
    Permalink to comment#

    i tried in many ways in .htaccess.txt file. But still no change. I think the issue may be some what different. Can anyone guess the issue?

    • Adam
      Permalink to comment#

      I am not sure if this is always the case but try getting rid of .txt from the file name, it should just be .htaccess and be aware that your OS (like on my Mac) may hide files that start with a ” . ”

      If push comes to shove, I name it without a dot, and perhaps with a .txt file type and then rename it once it has been uploaded to my server.

  28. Mohamed Asif
    Permalink to comment#

    Hi Kumar,
    I hope this may helps you,

    Options +FollowSymLinks

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}.php -f

    RewriteRule ^(.*)$ $1.php

    Its working for me..

  29. karan
    Permalink to comment#

    hi
    i am use below code but it’s not work in my localhost so please help me.

    RewriteEngine on
    RewriteBase /test/
    RewriteRule ^enquiry$ enquiry.html [L]

  30. Bimy
    Permalink to comment#

    Hi,

    I want to modified url in my site same as WordPress

    I have: http://mysite.com/5-remove-file-extention-from-urls.html

    How to rewrite to: http://mysite.com/remove-file-extention-from-urls

    htaccess

    RewriteRule ^page,([0-9]+),([0-9]+),([0-9]+)-(.).html(/?)+$ index.php?newsid=$3&news_page=$1&cstart=$2&seourl=$4 [L]
    RewriteRule ^page,([0-9]+),([0-9]+)-(.
    ).html(/?)+$ index.php?newsid=$2&news_page=$1&seourl=$3 [L]
    RewriteRule ^print:page,([0-9]+),([0-9]+)-(.).html(/?)+$ engine/print.php?news_page=$1&newsid=$2&seourl=$3 [L]
    RewriteRule ^([0-9]+)-(.
    ).html(/?)+$ index.php?newsid=$1&seourl=$2 [L]

    Thanks.

  31. Gergő
    Permalink to comment#

    Hello everyone,

    I am new in creating htaccess code and i have a problem whit it, which is very annoying.

    I am using the code written by Boris which could be perfect to me. My only problem is that when I click on the following link: http://mydomain.com/login/ or http://mydomain/login (which is actually http://mydomain.com/login.php) it redirects perfectly, but my href becomes as follows: mydomain.com/login/login.

    As I understand the last slash is considered to be the root so the program appends the url to it, but i don’t want to. How can I avoid this phenomena, what is my problem?

    Thanks for your help, in advance!

  32. Permalink to comment#

    Hello,

    I’ve read through and tried the .htaccess coding to no avail. I want to type in http://www.mydomain.com/greatpage and have it redirect to http://www.mydomain.com/greatpage.php

    I have created the .htaccess file on my site and pasted in the coding listed above. Nothing. I use Godaddy, if that means anything. I also use Smultron to code my site.

    Help me…

  33. chetan
    Permalink to comment#

    I want to change the my url
    from: http://domain-name/dir/page1.php
    to: http://domain-name/dir/?page1

    For this i have written following code in my .htaccess file:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+.php
    RewriteRule (.).php$ /dir/?$1 [L,R=301]
    RewriteRule (.
    )/$ $1.php [L]

    The URL gets changed to what i want perfectly. But the page remains the same.
    For example,
    Suppose i m on page1.php. When i click on menu ‘page2′ (page2),
    the url gets changed to “domainname/dir/?page2″ but browser dont show the ‘page2′ contents.
    I am not using any CMS. Its just a simple php website.

  34. venkatesh
    Permalink to comment#

    i was used the follwing code but not working for http://www.example.com/index.php to http://www.example.com/index

    kindly help the correct code and how to used the code for our php file if any send me the mail with screenshot .

    Thanks in advance..,

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php

  35. Do you have to change the way you link to internal pages once you’ve implemented this? If so, how?

  36. This one is my own creation;

    AddType text/x-component .htc
    RewriteEngine On
    RewriteBase /

    remove .php; use THE_REQUEST to prevent infinite loops

    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]

    Pastie Link below, copy and paste from the blog may bork it up :)

    http://pastie.org/6011480

    • Prasadh
      Permalink to comment#

      Hello Niall…
      I tried your code..
      changed php to html in the code
      however only ONE link is working from all links on the page.. others are showing “404” or access forbidden

      I also added
      Options -MultiViews as I am hosting with 1and1.com

      below is exact code I have used in the .htaccess for your reference

      Options -MultiViews
      AddType text/x-component .htc
      RewriteEngine On
      RewriteBase /organic-herbal

      remove .php; use THE_REQUEST to prevent infinite loops
      

      RewriteCond %{THE_REQUEST} ^GET\ (.).html\ HTTP
      RewriteRule (.
      ).html$ $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}.html -f
      RewriteCond %{REQUEST_URI} !/$

      RewriteRule (.*) $1.html [L]

      currently I have 4 pages for testing.. 1 is index.html
      and other 3 pages.

      I have tried numerous codes from various forums.. but not a single one is working..

      if you can help I will be glad..

      Prasadh

  37. FYI the above can be dropped into any Apache server and you can reference example.php or /example folders will also render correctly but dont put a file named foo.php and a folder called foo, Apache will get upset :)

    Hope it helps :)

  38. Juno
    Permalink to comment#

    Perfect Niall, just perfect thank you :)

    How would one tackle something a little more complex such as:
    http://127.0.0.1/demo/redux/index.php?p=example.txt

    • Should work if the .htaccess is in the root no, other wise you would have to specify the domain, which I think is the earlier lines;

      RewriteBase /

      This should leave GET variable clean in the URL without the index.php

  39. Permalink to comment#

    Niall Flynn’s code is the best one! It works just perfect on the http://www.equinelux.com

    I’ve tested 25 different solutions, and only this one makes my morning happy. Thank you Naill. And now I wonder – is it really needed for SEO, or it is just …. ?

  40. Yeah it is my baby, been working on it for a while, it does help with SEO, if anything I think it just makes sense not to show a file extension to a normal brochure audience.

  41. I have a standalone post here now for this http://www.niallflynn.com/seo-news/remove-file-extension-from-urls/ so anyone who needs help or wants to add to this can drop some code/comments in.

  42. Jack
    Permalink to comment#

    Hi,

    Brilliant post. Can anyone tell me how you can do it so it shows:

    http://www.test.com/test.php as http://www.test.com/anythinghere/test.com

    Thanks.

    Jack

  43. Helal
    Permalink to comment#

    Please try this :(works fine for me)

    Make a .htaccess file on your web root and paste below code……..

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}.html -f

    RewriteRule ^(.*)$ $1.html

    Note:Replace html with your file extension, eg:- php, htm, asp

  44. Alberto Chucuán
    Permalink to comment#

    This works for me but I was wondering, how could this be simplified..

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)/$ $1.php

    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)/$ $1.html

    RewriteCond %{REQUEST_FILENAME}.py -f
    RewriteRule ^(.*)/$ $1.py

  45. Gareth

    Hi,

    I have tried around 15 different codes to try and make the page load without .php at the end but none of them work.

    I have contacted my host and they advised that their is nothing on the server which should stop a mod rewrite.

    This is the latest one I have attempted. Do I need the file in a certain format. I downloaded the original blank htaccess file and opened it in Wordpad.

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)/$ $1.php

    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)/$ $1.html

    RewriteCond %{REQUEST_FILENAME}.py -f
    RewriteRule ^(.*)/$ $1.py

  46. Chika

    I’m having issue getting RewriteRule to work on my site. I’ve used the following code, but it doesn’t seem to be working. I really don’t know how to get it to remove the .php when the page is loaded.

    Thanks

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}.html -f

    RewriteRule ^(.*)$ $1.html

    • gat
      Permalink to comment#

      Try to remove the file extension from the href code in the HTML after putting that code in the .htaccess.

    • Chika

      I will try that now.

      thanks

    • Chika

      Hi Niall, I tried the code it works, but does the following
      1) when i put my mouse on the link for example on “About us” and look down it is showing aboutus.php, but when i click it it will display http://www.mysite/aboutus with out the a forward slash on the front.
      2) I don’t want people to see the .php when they place their cursor on the link before clicking

      Please your help will be appreciated.

      Thanks

  47. Oh that is easy just remove the .php link fro m you a href;

    So if you had;
    My Link

    Change it to;
    My Link

    This will fix it and then if someone tries to go to either /zyz.php or /zyz/ they will get the same thing :)

  48. pako69
    Permalink to comment#

    Hi
    Can someone tell me how to do this trick but within a subdomain ?
    eg:

    http://www.mysite.com/sub/about.php

    should be rewrite to :

    http://www.mysite.com/sub/about

    or

    http://www.mysite.com/sub/about/

    thanks

  49. http://www.niallflynn.com/seo-news/remove-file-extension-from-urls/

    As far as I remember it is the 3rd line RewriteBase / that needs to be changed.

    I would checkout here http://www.silverstripe.org/general-questions/show/5168

  50. Paul

    I need to REMOVE part of the file name /extension.

    From this:

    http://example.com/news/local/nameoffile.REMOVE.shtml

    to this:

    http://example.com/news/local/nameoffile.shtml

  51. Monika
    Permalink to comment#

    Hi, I tried this code on my clients website but it doesn’t work. Simply I want to change the URL

    http://www.ninacooke.co.uk/page.php?f=lorem

    into

    http://www.ninacooke.co.uk/page/lorem

    my first step was to make http://www.ninacooke.co.uk/page work so I used this code:

    RewriteEngine on

    RewriteBase /

    RewriteRule ^page$ page.php [L]

    but it doesn’t work. Can somebody please tell me how should I do it?

  52. Monika
    Permalink to comment#

    ok I’ve changed the code a bit into:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^page/([a-zA-Z0-9]+)/$ page.php?f=$1
    </IfModule>

    but it still doesn’t work…
    It should change

    http://www.ninacooke.co.uk/page.php?f=lorem

    into

    http://www.ninacooke.co.uk/page/lorem

    What do I do wrong?

  53. I would use the following for testing this http://htaccess.madewithlove.be I can help you with this but best you get a nice test environment as I hate giving ppl 500 errors :)

  54. Monika
    Permalink to comment#

    I made it work moving http://www.ninacooke.co.uk/page.php?f=lorem into http://www.ninacooke.co.uk/page/index.php?f=lorem and using this code:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule ^page/([a-zA-Z0-9]+)$ page/index.php?f=$1
    </IfModule>

    now http://ninacooke.co.uk/page/lorem works ok :)

  55. manoj
    Permalink to comment#

    this is cool

  56. Binod
    Permalink to comment#

    Hey Monika, you code is not working.
    Mine is localhost/d/page.php?id=contact and I have used your code..But its not working.

    RewriteEngine on
    RewriteBase /
    RewriteRule ^d/([a-zA-Z0-9]+)$ d/index.php?f=$1

    It should change to localhost/d/contact..But nothing happened????

  57. Permalink to comment#

    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    Worked fine for me, It looks like a lot of people are not realizing that in order for this to work, you need to navigate to the new URL without the extension ie . http://www.domain/help.php , you would browse to http://www.domain/help and the browser will load help.php…. it wont magically remove the .php extension if that is how you have typed in the URL or linked to the page with a href containing the .php extension.

    Hope that helps..

  58. Phil
    Permalink to comment#

    Or you know, avoid the total overkill of mod_rewrite for such a task and simply use

    Options MultiViews
    
  59. Sebin Simon
    Permalink to comment#

    I have a website with wordpress blog. I have removed the php extension of all files in the root folder using htaccess. when i access http://www.mydomain.com/blog, it redirects to 404 page. I created a htaccess inside wordpress folder with Rewrite engine off but no use .

    <IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    
    RewriteCond %{REQUEST_URI}  !(blog) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    redirect /index http://domain.com
    
    ErrorDocument 404 http://domain.com/
    </IfModule>
    

    Kindly take this issue into serious concern. Thanks in advance.

    • I’m having the same issue. Is there a work around for this? Any sub-directories inside the root will be redirected to 404.

      Anyone found a solution for this?

  60. Noman Sayyed
    Permalink to comment#

    how remove .php in my static website.

    please help.

  61. Noman Sayyed
    Permalink to comment#

    Thanks #Niall

  62. Sathi
    Permalink to comment#

    Normally we use like this

    after using .htaccess i get error for displaying image

    if i give full url means it display fine like this

    how to access my image without giving this url

    Please give any suggestions

  63. M. Nayyar Islam
    Permalink to comment#

    Hi! I am having a blogger and like other website’s cPanel, I am unable to find the .htaccess file which is in hidden shape. Please let me know that “How could I find the .htaccess file” in the root directory of my blogger, or I may allow, if created a new one .htaccess file for my blogger. Kindly solve my problem. Thanks and Best Regards for all the Readers.

  64. Marcel

    I can’t get the trailing slash to work. When I use a version that has it, I get a 404. Please help.

  65. arpita
    Permalink to comment#

    Hello,

    I am working on one website..I have a problem in .htaccess file when i hide url .php its work on localhost perfectly but when i upload on live site or server it may get error 404 file or directory not found…

    I will change all the thing like http.conf mod enable and all that.. but no result found
    my lots of time waste on this topic but no any output so plzzzz help me..

    thank you in advance..
    I am waiting for yours reply…

  66. Frank
    Permalink to comment#

    I don’t know about this. I would think removing your extensions would be problematic at best. I am seeing this more and more, but I can’t help but think it is a mistake. I would definitely not use the trailing slash because it represents a directory. Maybe for a small site or blog, but for a large website it seems to carry too much risk. What about all of the links already pointing to your pages? I believe you have to change all of your internal links. CSS files and images might stop working. It just seems to be a huge risk for higher traffic website, especially.

    When is the last time you typed in a URL to a nested web file? Most use a link. Stores like Amazon do not do this and they dominate the web. I question whether there is really any SEO value.

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".