SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Will this .htaccess code work?

    Code:
    RewriteEngine  on
    
    RewriteRule ^index.html$ index.php
    RewriteRule ^realisations.html$ realisations.php
    RewriteRule ^roofing-services-montreal/roofing.html$ roofing.php
    I'm new to mod_rewrite, and it's either my server doesn't support the module or I'm doing something wrong.
    Should the code above work properly if uploaded to www.website.com/.htaccess ?

    Basically I'm trying to change specific .php pages to .html, and give some pages a fake sub-directory extension, will this work?
    Thank you very much in advance.

  2. #2
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    If this is Apache 2.x, then yes it should work and indeed, a .htaccess file in the root of your website is correct as well.

    If it is Apache 1.x --highly unlikely since I don't think anyone uses that anymore-- it will not work, you'd need to change every ^ with ^/

    Also, you need to escape dots in the filename, like this

    Code:
    RewriteEngine  on
    
    RewriteRule ^index\.html$ index.php
    RewriteRule ^realisations\.html$ realisations.php
    RewriteRule ^roofing-services-montreal/roofing\.html$ roofing.php
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi megashape,

    Have you checked if your Apache server has mod_rewrite loaded? This needs to be loaded in the apache2,conf. Typically in Debian based distributions in root->etc->apache2->mods-enabled you need a rewrite.load like
    Code:
    LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
    . If you have this in there or in your main apache2.conf file and apache starts without errors then it should be loaded.

    As you are using php you can also create a php page that has only:
    Code:
    <?php
    phpinfo();
    ?>
    or somewhere in one of the pages that you are trying to have a redirect to occur use:
    Code:
    <?php
    print_r(get_loaded_extensions());
    ?>
    
    Steve

    Quote Originally Posted by megashape View Post
    Code:
    RewriteEngine  on
    
    RewriteRule ^index.html$ index.php
    RewriteRule ^realisations.html$ realisations.php
    RewriteRule ^roofing-services-montreal/roofing.html$ roofing.php
    I'm new to mod_rewrite, and it's either my server doesn't support the module or I'm doing something wrong.
    Should the code above work properly if uploaded to www.website.com/.htaccess ?

    Basically I'm trying to change specific .php pages to .html, and give some pages a fake sub-directory extension, will this work?
    Thank you very much in advance.
    ictus==""

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    SS,

    Good thought but mod_rewrite code on a server where it's not loaded and enabled would generate syntax errors which cause 500 errors to be sent, i.e., it's enabled.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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