.htaccess file extension removal problem...

Discussion in 'Site & Server Administration' started by Mr.Dog, Oct 9, 2012.

  1. #1
    Hello,

    I have some issues with an .htaccess file code...

    I want to:
    - remove the file extension from the URL
    - and replace it with a "/" at the end...

    This is my code I've added and it's not working at all!

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.htm -f
    RewriteRule ^(.*)$ $1.htm
    # Replace htm with your file extension, eg: php, htm, asp


    # Forces a trailing slash to be added
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]

    Basically it should replace ".htm" with "/"

    It's not working at all.
     
    Mr.Dog, Oct 9, 2012 IP
  2. badolfus

    badolfus Greenhorn

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    8
    #2
    Please copy and paste the following code to your .htaccess file:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+)$ $1.php [L,QSA]

    Once this file has been uploaded to the root directory on your web server, the ".php" extension will no longer be required in your URL's to access pages.
     
    badolfus, Oct 9, 2012 IP
  3. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Should be .htm, since I have .htm extensions, right?

    Anyway, I tried it your way with .htm instead of .php, but still doesn't work.

    What could the cause of the problem be? And what could the solution be?
     
    Last edited: Oct 9, 2012
    Mr.Dog, Oct 9, 2012 IP
  4. badolfus

    badolfus Greenhorn

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    8
    #4
    Sorry for the inconvenience

    Please copy and paste the following code once in your .htaccess file, and I hope this time it will work:


    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html
     
    Last edited: Oct 10, 2012
    badolfus, Oct 10, 2012 IP
  5. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Unfortunately it isn't working... shouldn't it also contain this?

    RewriteBase /

    Meanwhile I contacted the hoster, but they are unaware of any setting blocking this from their side
     
    Mr.Dog, Oct 10, 2012 IP