【问题标题】:Redirect to another page instead of index.php through htaccess通过 htaccess 重定向到另一个页面而不是 index.php
【发布时间】:2014-03-24 21:21:20
【问题描述】:

当第一次加载页面而不是索引页面时,它应该重定向到另一个页面。 之后,当我们单击主页时,它将重定向到主页。我已经通过 htaccess 完成了。 我也想打开数据库链接,所以我把代码放在下面。

DirectoryIndex inventory.php

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

以上代码仅适用于首次页面加载,但重写规则不起作用。如果我要评论第一行,则重写规则有效,但目录索引无效。但我两者都想要。我该如何解决。

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    取决于您的确切需求,我使用 cookie 在您首次访问时重定向您。 第一次访问时,index.php 将找不到 cookie 并转到 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>
    

    【讨论】:

      【解决方案2】:

      在 .htaccess 文件上试试这个:

      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] 
      

      【讨论】:

        猜你喜欢
        • 2011-07-09
        • 2016-12-19
        • 1970-01-01
        • 2017-08-10
        • 1970-01-01
        • 2014-01-07
        • 2014-05-17
        • 2015-06-24
        • 2014-08-10
        相关资源
        最近更新 更多