SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can i set my sites index.html to home page ?

    I have a PHP based sites .i want to redirect index.html page to home page .how can i do .i have tried many time but it give error
    my sites is this :- <snip />
    Last edited by guido2004; Dec 5, 2011 at 05:23. Reason: no need for url

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,412
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    Looks like a rewrite question to me. Moved to the apache forum.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your home page is index.php, just delete index.html from the server and your index.php will be automatically picked up as the home page. Not quite sure what you are trying to do exactly so sorry if this is not what you were looking for.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    elwin,

    chilli11's answer is true only with a caveat: Your DirectoryIndex must be set to index.html index.php {anything else}.

    Somehow, I don't believe this is a mod_rewrite question (redirect a specific filename to a different filename) so you have several choices depending upon your real intention:
    Code:
    # DirectoryIndex solution, i.e., specify the default files to be served in order of appearance
    DirectoryIndex index.php index.html index.htm default.asp
    
    # mod_alias (Apache core) solution
    Redirect 301 index.htm /index.php
    # here, the redirection is specified to be permanent (301 code) and the redirection MUST be an absolute URI/URL
    
    # mod_rewrite solution
    RewriteEngine on
    RewriteRule ^index\.html?$ index.php [R=301,L]
    # here the regular expression will capture index.htm or index.html
    # (? denotes that the previous character is optional),
    # ^ is the start anchor (the beginning of the {REQUEST_URI} string),
    # $ is the end anchor (the end of the {REQUEST_URI} string}, 
    # R=301 is a permanent redirection and L says to end that RewriteRule set
    # (the set can be "attached" to RewriteCond and other RewriteRule statements)
    If you're interested in the POWER that regular expressions give a webmaster, have a look at the tutorial Article linked in my signature.

    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

  5. #5
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. add index.html on your DirectoryIndex configuration of your vhost or httpd.conf

    or.

    2. create a index.html and add a redirect on it ex:
    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.abc.com/");
    exit();
    ?>

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    tric,

    Aw, if you do this, you'll need to add an AddHandler so PHP will know to parse and run the code in an .html file. Obviously, the DirectoryIndex is the preferred (and intentionally so) way to have index.php loaded as the default script (if it's available).

    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

  7. #7
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elwinjones View Post
    I have a PHP based sites .i want to redirect index.html page to home page .how can i do .i have tried many time but it give error
    my sites is this :- <snip />
    Hi,
    Try use this code in .htaccess:
    Code:
    #RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^domain.net/index.html$ domain.net/index.php [R=301]
    - replace "domain.net" with your site name.

    If not work, you can use this html meta tag in the header of the index.html
    Code:
    <meta http-equiv="refresh" content="0;url=index.php" />
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    MarPlo,

    VERY bad recommendation - primarily because the RewriteRule can only examine the {REQUEST_URI} Apache variable (which will never contain the domain name). Further, the RewriteBase (which is commented out) is totally irrelevant (no mod_alias Redirects to "undo") and the question (and solution) has nothing to do with the requested file being a file or directory which exists.

    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

  9. #9
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thank you for correction, we allways have something to learn.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    MarPlo,

    No worries, mate!

    What you were showing was the standard CMS (WP) mod_rewrite code which redirects EVERYTHING except existing files and directories to index.php. Nice as a 404 handler but that wasn't the question that was asked. On the other hand, the DirectoryIndex Apache core directive was designed to give a "shopping list" of files for Apache to check for in the event only a directory was specified, ergo, that's the directive to use.

    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
  •