dongli9894 2011-04-24 22:27
浏览 10
已采纳

Mod重写斜线问题

I searched this problem in the site, but I couldn't find a solution.

I have a php page, call http://www.domain.com/topic.php?name=xyz

I want to call this page with http://www.domain.com/topic/xyz

What I tried is;

RewriteEngine On

RewriteRule ^topic/([^/]*)$ /topic.php?name=$1 [L]

However because of this "/" I get 404 error. If I try "-" instead of "/" it works. I guess "/" forward user to folder "/topic" so I need a solution to fix it.

  • 写回答

5条回答 默认 最新

  • douyan1903 2011-08-22 10:06
    关注

    I found my solution to problem. It is a bit late though :)

    I edit my .htaccess such that

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule .* redirect.php [L] 
    

    I create a redirect.php as you see. In this file, I explode slashes, then by using if statement I set

    $path =  explode("/", $_SERVER['REQUEST_URI']);
    switch ($path[1])
    {
        case 'topic': $_GET[name]=$path[2]; include('topic.php'); break;
    }
    

    As you see setting $_GET as a code isn't handsome, but it works like a charm! :) Thanks all for your helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序