Skip to main content

hide .php extension - htaccess



Possible Duplicate:

remove .php extension with .htaccess




Hey guys I'm trying to hide the .php file extension but for some reason can't get it to work, my latest attempt was the following




<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^folder/([a-zA-Z_\-0-9]+)/?$ /folder/$1.php
</IfModule>



I have tried many different variances of code I have found online but still no luck, the .htaccess file is placed within the root directory.



The site I am trying to get this to work on is http://www.ashleysark.com/



Thanks in advance Adam


Source: Tips4allCCNA FINAL EXAM

Comments

  1. I've used this:

    RewriteEngine On

    # Unless directory, remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

    # Redirect external .php requests to extensionless url
    RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

    # Resolve .php file for extensionless php urls
    RewriteRule ^([^/.]+)$ $1.php [L]


    see also: this question

    ReplyDelete
  2. The other option for using PHP scripts sans extension is

    Options +MultiViews


    Or even just following in the directories .htaccess:

    DefaultType application/x-httpd-php


    The latter allows having all filenames without extension script being treated as PHP scripts. While MultiViews makes the webserver look for alternatives, when just the basename is provided (there's a performance hit with that however).

    ReplyDelete
  3. 1) Are you sure mod_rewrite module is enabled? Check phpinfo()

    2) Your above rule assumes the URL starts with "folder". Is this correct? Did you acutally want to have folder in the URL? This would match a URL like:

    /folder/thing -> /folder/thing.php


    If you actually want

    /thing -> /folder/thing.php


    You need to drop the folder from the match expression.

    I usually use this to route request to page without php (but yours should work which leads me to think that mod_rewrite may not be enabled):

    RewriteRule ^([^/\.]+)/?$ $1.php [L,QSA]


    3) Assuming you are declaring your rules in an .htaccess file, does your installation allow for setting Options (AllowOverride) overrides in .htaccess files? Some shared hosts do not.


    When the server finds an .htaccess file (as specified by
    AccessFileName) it needs to know which directives declared in that
    file can override earlier access information.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?