【问题标题】:I want to redirect website visitor from "expl.com/... "to "expl.com/index.php/..."我想将网站访问者从“expl.com/...”重定向到“expl.com/index.php/...”
【发布时间】:2019-12-31 09:05:06
【问题描述】:

这是我的域名http://cdtr.cf 它位于 index.php
我在其中编写了一些代码,该代码从 URL 框中提取 URL 并修剪其后缀以识别访问者的身份。 问题是当有人打开 http://cdtr.cf/.... 时显示错误 404 page not found

虽然 http://cdtr.cd/ 工作正常。我只需要当有人访问http://cdtr.cf/.... 时,他们必须被重定向到index.php,并且他们的请求应该像http://cdtr.cf/index.php/.... 一样处理。 出于某种目的,我想保留后缀:-http://cdtr.cf/suffix
如果这一切都发生在 URL 框中没有任何可见的变化,那就太好了。

提前致谢。

    $link= (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=== 'on'? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];  
    echo $link;  //It is working fine on localhost but not when i put it live

【问题讨论】:

  • 我试图让您的问题更具可读性。但是它缺少一个非常重要的部分:代码。您能否edit the question 并将代码添加为格式化文本(not 作为图像)?
  • 似乎应用了一些重写规则。这些规则是@LaurenzAlbe 所指的代码。你需要找出这些规则。
  • 我编辑了问题并需要帮助,请@LaurenzAlbe
  • @arkascha 请帮帮我

标签: php apache .htaccess url url-rewriting


【解决方案1】:

此代码将根据您的要求为您提供其余的网址

<?php
$link = $_SERVER['REQUEST_URI'];
echo $link = ltrim($link, '/');

//if you want you can trim last / too using $link = rtrim($link, '/');
?>

如果您想获得类似 yoursite.com/stuffs/removedthis 的中间件

那么你必须使用下面的代码

<?php
$link = $_SERVER['HTTP_HOST'];

$link .= $_SERVER['REQUEST_URI'];
$link = explode('/', $link);

echo $a = $link[1];
?>

第二个例子:

$link = "example.com/stuff/removethis/....blah";
$link = explode('/', $link);
echo $a = $link[1];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2016-03-02
    • 2017-09-25
    • 2013-02-15
    相关资源
    最近更新 更多