简体   繁体   English

如何将我的页面重定向到index.php?

[英]How to redirect my pages to index.php?

I would like to know why when I go on my site http://nextgenfocus.com/ , index.php does not in the URL and the content is not fully displayed. 我想知道为什么当我进入网站http://nextgenfocus.com/时 ,index.php不在URL中并且内容没有完全显示出来。 I tried with a .htaccess file, but nothing helped. 我尝试使用.htaccess文件,但没有任何帮助。

My index.php file: 我的index.php文件:

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="UTF-8">
        <?php
        if(strpos($_SERVER["REQUEST_URI"], "index.php") !== false) { ?>
        <title>Test - Home</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["REQUEST_URI"], "downloads") !== false) { ?>
        <title>Test - Downloads</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["REQUEST_URI"], "help") !== false) { ?>
        <title>Test - Help</title>
        <?php } ?>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <?php include("top_bar.php");?>
        <?php include("container.php");?>
        <?php include("footer.php");?>
    </body>
</html>

How I can do, please? 请问我该怎么办?

尝试配置您的httpd配置并添加DirectoryIndex以默认执行index.php(如果在该路径中找到)。

DirectoryIndex index.php index.phtml index.html index.htm

Anyway, if you really want to redirect via Apache you should paste this code in your .htaccess 无论如何,如果您确实要通过Apache重定向,则应将此代码粘贴到.htaccess中

RewriteEngine on Redirect / /index.php

BE SURE that your apache has mod_rewrite enabled 确保你的Apache已经启用的mod_rewrite

Add this in your container.php file 将此添加到您的container.php文件中

 <?php if((strpos($_SERVER["REQUEST_URI"], "index.php") !== false) && (strpos($_SERVER["REQUEST_URI"], "/") !== false)){ ?>
     <div id="container">
         <!-- Your code here -->
     </div>
<?php } ?>

You're trying to match on request uri, that is what you read on your browser address box. 您正在尝试根据请求uri进行匹配,这就是您在浏览器地址框中读取的内容。 You shold match on $_SERVER['SCRIPT_FILENAME'] index 您在$_SERVER['SCRIPT_FILENAME']索引上保留匹配项

you could use this code for matching your page: 您可以使用以下代码来匹配您的页面:

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="UTF-8">
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "index.php") !== false) { ?>
        <title>Test - Home</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "downloads") !== false) { ?>
        <title>Test - Downloads</title>
        <?php } ?>
        <?php
        if(strpos($_SERVER["SCRIPT_FILENAME"], "help") !== false) { ?>
        <title>Test - Help</title>
        <?php } ?>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <?php include("top_bar.php");?>
        <?php include("container.php");?>
        <?php include("footer.php");?>
    </body>
</html>

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

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