dougou8552 2018-05-24 16:02
浏览 24

将index.php移动到另一个目录

I am using this GitHub page: https://github.com/Athlon1600/php-proxy-app and as it's supposed to, when I go to development.stech.software it loads up index.php.

When I choose a link, it makes it a query string like this development.stech.software/index.php?q=y6ml06abkWPdp6pnn6PVl6TLlMSkpmdvzdzUj6WZbqbWoQ (where the random characters is the query).

How do I adjust the index.php file, so that when I go to a URL, it loads it on /index.php/query/y6ml06abkWPdp6pnn6PVl6TLlMSkpmdvzdzUj6WZbqbWoQ or something similar.

I tried this, but it wouldn't work (it reported 500), I found it from URL rewriting with PHP

$path = ltrim($_SERVER['REQUEST_URI'], '/');    // Trim leading slash(es)
$elements = explode('/', $path);                // Split path on slashes
if(empty($elements[0])) {                       // No path elements means home
    ShowHomepage();
} else switch(array_shift($elements))             // Pop off first item and switch
{
    case 'index':
        ShowPicture($elements); // passes rest of parameters to internal function
        break;
    case 'more':
        ...
    default:
        header('HTTP/1.1 404 Not Found');
        Show404Error();
} 

I also added this to .htaccess FallbackResource htdocs/index.php

  • 写回答

1条回答 默认 最新

  • duanji1899 2018-05-24 16:26
    关注

    To redirect /index.php?q=foobar to /index.php/query/foobar you can use the following Rule in your htaccess file:

     FallbackResource htdocs/index.php
    
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^q=(.+)$
    RewriteRule ^index.php$ /index.php/query/%1? [L,R]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错