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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.