duanji5569
duanji5569
2014-03-24 13:02

通过htaccess重定向到另一个页面而不是index.php

已采纳

When first time load the page instead of index page it should redirect to another page. After that when we clicked on home page then it will redirect to home page. I have done through htaccess. And I wanted to open database link also so I put below code.

DirectoryIndex inventory.php

< IfModule mod_rewrite.c >
  RewriteEngine on
  Rewriterule ^mega_dados/.*$ - [PT]
</IfModule >

Above code is working only for first time page load but rewrite rule is not working. If I'll comment first line then rewrite rule is working but directory index is not working. But I wanted both. How can I resolve it.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douyiavxxh02727 douyiavxxh02727 7年前

    Depends what you need exactly, i use cookies to redirect you at first visit. By the first visit, index.php will not find a cookie and goes to start.php

    index.php:

    <?php
        if (!isset($_COOKIE['MYcookie'])) {
            header("Location: ./start.php");
            exit();
        }
    ?>
    

    start.php:

    <?php 
      if (!empty($_POST['waarde'])) 
      {  
            setcookie ('MYcookie', 'yes', time() + 3600);
            header("Location: ./index.php");
            exit();
      }
    ?>
    
          <form method="post" action="">
          <input type="radio" name="waarde" value="1" checked="checked"><b>YES</b>
          <input type="radio" name="waarde" value="0"><b>NO</b>
          <input class="mybuttons" type="submit" value="ACCEPT">
          </form>
    
    点赞 评论 复制链接分享
  • dongwu5318 dongwu5318 7年前

    Try This on .htaccess file:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www\.example\.com/$1 [R=301,L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.{htm|html|php)\ HTTP/
    RewriteRule ^(([^/]+/)*)index\.(htm|html|php)$ http://example.com/$1 [R=301,L] 
    
    点赞 评论 复制链接分享

为你推荐