简体   繁体   English

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

[英]Redirect to another page instead of index.php through htaccess

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. 我已经通过htaccess完成了。 And I wanted to open database link also so I put below code. 而且我也想打开数据库链接,所以我在下面的代码。

DirectoryIndex inventory.php DirectoryIndex目录.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. 我该如何解决。

Depends what you need exactly, i use cookies to redirect you at first visit. 根据您的确切需求,我会在第一次访问时使用cookie来重定向您。 By the first visit, index.php will not find a cookie and goes to start.php 第一次访问时,index.php将找不到cookie,而是转到start.php。

index.php: index.php文件:

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

start.php : 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>

Try This on .htaccess file: 在.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] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM