Results 1 to 4 of 4

Thread: rewrite file extention in htaccess

  1. #1
    RCull is offline Nearly a Glow Sage
    Join Date
    Dec 2014
    Posts
    19

    Default rewrite file extention in htaccess

    I have changed many file extensions from html and shtml to .php.

    Is it reasonable to have a rewrite rule that takes requests for "non-existent" .html and .shtml files and rewrites them for .php with the same name or should I stick with a simple line redirecting each file?

    Thanks

  2. #2
    AndrewGlow is offline Master Glow Jedi
    Join Date
    Sep 2009
    Posts
    1,232

    Default

    Hello,

    I would use an editor that has a "Replace all" function to update script links in all places. A rewrite rule may also work, but it is not the correct configuration and, from my point of view, may cause some troubles in the future.

    For example, what if you have had some page.html and removed it? Then while accessing this page, instead of getting a 404 error, the user will be redirected to page.php and only after that will get 404 error. It is not too much "work" for the server and not too much "load", but still not the ideal approach.
    Last edited by GlowHost-Daniel; 09-21-2015 at 05:11 PM.
    Have no fear,
    GlowHost is Here!

  3. #3
    RCull is offline Nearly a Glow Sage
    Join Date
    Dec 2014
    Posts
    19

    Default

    On my site, I have corrected all the extensions. What I am trying to address is offsite requests for old html extensions.

    It is a fair amount of work, but perhaps a simple redirect is best?

    Redirect 301 /reference/years/50.shtml http://www.*****.com/reference/years/50.php

    Thanks

  4. #4
    David I is offline Newbie
    Join Date
    Jun 2010
    Posts
    1,242

    Default

    Hello,

    Here is how you can do that:

    Code:
    RewriteEngine on RewriteRule ^(.*).html$ $1.php
    Or more advanced way:
    Code:
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\.html$ $1.php?%{QUERY_STRING} [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*$ index.php [L]

Similar Threads

  1. [How To] Create or edit the .htaccess file
    By AndrewGlow in forum Knowledge Base
    Replies: 0
    Last Post: 01-23-2011, 09:51 AM
  2. htaccess and mod_security
    By omarfilip in forum General Support
    Replies: 2
    Last Post: 01-21-2010, 02:03 PM
  3. .htaccess, config settings, or what?!
    By rlhanson in forum WHM, Resellers, VPS and Dedicated Hosting Topics
    Replies: 10
    Last Post: 11-08-2007, 11:22 AM
  4. Ultimate .htaccess Tutorial
    By Kai in forum Programming Talk
    Replies: 4
    Last Post: 06-15-2007, 03:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14