Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other hide .html with .htaccess not working – Please Help

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #37722
    Rugg
    Participant

    Hello!

    I am attempting to hide the .html file extension in the url – and redirect when manually typed in. I am using the .htaccess to accomplish this, however I am not seeing any results. Any help is much appreciated. Thank You.

    The code:

    <br />
    <br />
    RewriteCond %{REQUEST_FILENAME} !-d<br />
    RewriteCond %{REQUEST_FILENAME}.html -f<br />
    RewriteRule ^(.*)$ $1.html<br />
    <br />
    
    #101574
    Staggers
    Member

    Did you set the base and turn the engine on before hand?

    RewriteBase /

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

    @NSR

    Here is an answer from stackoverflow.com:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ $1.html [NC,L]

    If the person tried adding a .html extension to the URL, wouldn’t it automatically be removed with the code above?

    #108572

    @NSR
    Would you name the file name.htaccess in order for the file to work?

    #108574
    JohnMotylJr
    Participant

    @NSR, this is a little off subject but i was wondering what would you be using this for? The reason i am asking because i have seem methodology before but im only a college student and havent really seen any implementation for this. So basically, what real world scenario are you trying to achieve by removing the extension?

    Good luck with finding the answer btw.

    #108581
    Odd_E
    Member

    Well the code that Chris wrote in the PHP snippets works just fine, but you have to link to /about rather than /about.html or something

    #110122
    drench
    Member

    i want to hide url in subdirectory
    http://www.123musiq.biz/folder/page.html
    to
    http://www.123musiq.biz/folder/page

    .htaccess tag added in subdirectory but it doesn’t work.
    the tag is
    RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^(.*)$ $1.html
    what can ido? what is the code for hide url extension in subdirectory file?

    #110880
    dona
    Member

    Hello all user i want hide page how can i do? this my url **http://khmerera.com/detail.php?ads=$id** but now i want hide detail.php how can i do it i want have like this **http://khmerera.com/?ads=$id **please help me Thz!

    #113344
    chrisburton
    Participant

    Basically it makes them look “pretty”.

    #123358
    cuoicaicoi
    Member

    @Rugg:
    Hi Rugg, I follow your code below

    RewriteCond %{THE_REQUEST} /(.+/)?index(.html)?(?.*)? [NC]
    RewriteRule ^(.+/)?index(.html)?$ /%1 [R=301,L]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^(.+).html$ /$1 [R=301,L]

    RewriteCond %{SCRIPT_FILENAME}.html -f
    RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]

    and it works fine.
    However, because I use 2 files for contact page which is contact.html and contact.php
    When I type /contact the html page cannot load.

    Do you know why does it happen and how to fix it?
    Thanks a lot.

    #135690
    sgotmare
    Member

    **I there I Am new with httacces **

    Extension .html but i can hide using this rule .. help

    #146324
    paulw
    Participant

    Hi All,

    I can’t get this to work at all :-/

    The pages load fine, I get no errors, but the .html extensions are still visible in the browser, any ideas?

    Code:

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteBase /
    RewriteEngine on
    RewriteCond %{REQUEST_fileNAME} !-d
    RewriteCond %{REQUEST_fileNAME} !-f
    RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [L]
    </IfModule>

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Other’ is closed to new topics and replies.