Forums

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

Home Forums Other A more in depth look at mod_rewrite .htaccess rules!

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #34516
    standuncan
    Member

    I have researched until my brain hurts numerous times. Removing the extension in the browser should rather be an easy rewrite rule. I have found four different ways and yet again, none of them are working.

    Granted, the current site is hosted on godaddy, however I have used one of these methods before on this same hosting and it has worked before, however only some of the time?

    Yes it is an Apache server.
    Yes mod_rewrite is enabled.
    Yes I am removing the extension in the href links.

    First and most common method I believe, not working:



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

    Second method with a failed attempt:



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

    Third way which is failing:



    RewriteRule ^index$ index.php [L]
    RewriteRule ^page$ page.php [L

    And lastly, I think is the correct way since it actually rewrites the link appending the extension, however still failing (this is the method that has worked before):



    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

    Any help greatly appreciated…

    #87991
    chrisburton
    Participant

    @standuncan – Where are you putting the file?

    #87994
    standuncan
    Member

    I have the .htaccess file at the root level, for this site.

    However, this site is in a sub-directory of a shared hosting account with a separate domain directing to this sub-directory. I know the .htaccess file will only affect what is at the same or within that level.

    #87996
    chrisburton
    Participant

    So you have a redirect to that specific subdirectory?

    #88001
    standuncan
    Member

    Maybe I’m explaining it wrong, it’s setup in the hosting panel that this sub-directory is the root folder. Not a true redirect.

    #88004
    chrisburton
    Participant

    @standuncan – I’m totally confused. You have the .htaccess at the very root level yet have the site in a subdirectory. Is that what you’re saying?

    If not, take a screenshot of your file structure.

    #88170
    standuncan
    Member

    Well I kept messing with it, but I couldn’t get it. So I just swapped the extensions to .html instead of .php using:



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

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