简体   繁体   English

我主页的PHP URL

[英]PHP URL for my homepage

so I'm editing a PHP site (I'm a Python guy). 所以我正在编辑一个PHP网站(我是Python专家)。 What I need is a way to maybe redirect such that when someone navigates to the site eg www.mysite.com , the homepage should be served. 我需要的是一种可能重定向的方法,以便当有人导航到网站www.mysite.com ,应提供主页。 The system used to serve other pages is as sush: to navigate let's say to the contacts page, we use www.mysite.com?page_id=contact-us . 用于提供其他页面的系统很麻烦:假设导航到联系人页面,我们使用www.mysite.com?page_id=contact-us The query string helps the server side code to know what page to serve. 查询字符串可帮助服务器端代码知道要服务的页面。 So what I want is that when a user navigates to the site by typing www.mysite.com , he should get to the page www.mysite.com?page_id=home . 因此,我想要的是,当用户通过输入www.mysite.com导航到该站点时,他应该进入www.mysite.com?page_id=home页面。

Thank you. 谢谢。

Sample code: 样例代码:

$page = isset($_GET['page_id']) ? $_GET['page_id'] : null;
    if ($page !== null) {
            //redirect to correct page
        require("modules/inside.php");
    } else {
            //redirect to 'home'
        header('Location: https://www.ndovucard.com?page_id=home');
        require("modules/home.php");
    }

Try... 尝试...

if (!isset($_GET['page_id'])){
   header('Location: www.mysite.com?page_id=home');
}

Something like this? 像这样吗

$page = (isset($_GET['page_id'])) ? $_GET['page_id'] : 'home';
echo $page; // 'home' or provided page_id

From what you've said it sounds like you need a: 从您所说的看来,您需要:

if (!isset($_GET['page_id'])) $_GET['page_id'] = 'home';

Personally I prefer a full URL rewrite system rather than passed by URL query as it's believed search engines prefer contact-us.html rather than page_id=contact-us 我个人更喜欢完整的URL重写系统,而不是通过URL查询传递,因为它认为搜索引擎更喜欢contact-us.html而不是page_id = contact-us

Edit: You could alternatively do: 编辑:您可以选择执行以下操作:

if (!isset($_GET['page_id'])) {
    header('Location: /?page_id=home');
    die(); // stop any further processing
}

something like: 就像是:

$page = isset($_GET['page_id']) ? $_GET['page_id'] : 'home';
/* check that page is a valid page else serve error page */
/* then redirect to the correct $page */
header('Location: www.mysite.com?page_id=' . $page);
exit();

By the way, you need some way to check that $_GET['page_id'] is always a valid page_id before redirecting. 顺便说一句,您需要某种方法在重定向之前检查$_GET['page_id']始终是有效的page_id

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

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