301 redirect from "/index.html" to root if index.html not exist

2,423

Use it like this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*?/|)index\.html$ / [L,R=301,NC]
Share:
2,423

Related videos on Youtube

ayublin
Author by

ayublin

Updated on September 18, 2022

Comments

  • ayublin
    ayublin over 1 year

    Possible Duplicate:
    How to enable PHP short tags ?

    I am using

    Apache Friends XAMPP (Basis Package) version 1.7.3
    • Apache 2.2.14 (IPV6 enabled)
    • MySQL 5.1.41 (Community Server) with PBXT engine 1.0.09-rc
    • PHP 5.3.1 (PEAR, Mail_Mime, MDB2, Zend)

    and i am running php files, that i code with <? ?> tags not <?php ?>. but the apache server won't execute my code, but if i try with <?php ?> tags, the code works. Anyone know how to enable the server to execute php code with <? ?> tags ?

    • zerkms
      zerkms over 13 years
      Why don't you use <?php then everywhere, the less configuration-dependent way of specifying php code?
    • profitphp
      profitphp over 13 years
      Its best to not use short tags though, they are on the way out, and you will someday have to go and change them all.
    • Marc B
      Marc B over 13 years
      You can enable the short tags, but take it as a sign that you'll have to start updating your code: short tags are deprecated and could vanish in any future version of PHP, leaving you with a large pile of unusable code.
    • netcoder
      netcoder over 13 years
      @Marc B: Short tags are not deprecated, although I agree they should not be used.
    • ayublin
      ayublin over 13 years
      @jasonbar: ohh yeah, it's also answer to my problem, sorry i didn't realized it's existencene before, should i delete this ? @all: ohh, well, thank you very much everyone, i don't know if it's deprecated, so it's better for me change everything before it's too late.. once again thanks!
    • Marc B
      Marc B over 13 years
      Ah, I see now that the decision was made to leave them in. Good enough. Thanks for getting me to go look.
    • Felix Kling
      Felix Kling over 13 years
      @Marc B: They might not be deprecated but that they are disabled by default is a strong sign not to use them.
  • ceejayoz
    ceejayoz over 13 years
    Well, he needs to stop using short tags. This is just a temporary workaround until the ability to use them disappears entirely.
  • Admin
    Admin about 11 years
    Doesn't work, this rule show 310 redirect on all pages. (I mean firs rule) 2nd rule don't change anything
  • Admin
    Admin about 11 years
    Try this one RewriteEngine On RewriteCond %{REQUEST_FILENAME} ^(.*)/index.html$ RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^.*$ - [NC,L] RewriteRule ^(.*)/index.html$ /test.php?a=$1 [R=301,L,NC]
  • Admin
    Admin about 11 years
    RewriteRule is not properly visible in comments, so updated by answer
  • Admin
    Admin about 11 years
    The same 404error Thanks for try, maybe you know where can be this problem?
  • Admin
    Admin about 11 years
    can you check Firebug -> Net? Is RewriteRule is giving 404 or it gives 404 after redirecting to example.com/$1
  • Admin
    Admin about 11 years
    Doesnt work, maybe you know reason for this?
  • Admin
    Admin about 11 years
    Have you ever tried to run the code by itself? Now, check the updates' new code if it will going to work.
  • Admin
    Admin about 11 years
    Only 404 without redirect