Mod重写斜线问题 [英] Mod Rewrite Slash Problem
问题描述
我在网站上搜索了此问题,但找不到解决方案.
I searched this problem in the site, but I couldn't find a solution.
我有一个php页面,请致电 http://www.domain.com/topic.php?name=xyz
I have a php page, call http://www.domain.com/topic.php?name=xyz
我想用 http://www.domain.com/topic/xyz
我尝试过的是
RewriteEngine开启
RewriteEngine On
RewriteRule ^ topic/([[^/] *)$/topic.php?name=$1 [L]
RewriteRule ^topic/([^/]*)$ /topic.php?name=$1 [L]
但是由于这个"/",我收到404错误.如果我尝试使用-"而不是"/",那么它可以工作.我想"/"会将用户转发到文件夹"/topic",所以我需要一种解决方案来解决它.
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.
推荐答案
我找到了解决问题的方法.不过有点晚了:)
I found my solution to problem. It is a bit late though :)
我编辑.htaccess文件是这样的,
I edit my .htaccess such that
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule .* redirect.php [L]
如您所见,我创建了一个redirect.php.在此文件中,我将斜线爆炸,然后使用if语句设置
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;
}
如您所见,将$ _GET设置为代码虽然不算很帅,但它的工作原理却很吸引人! :)谢谢大家的帮助.
As you see setting $_GET as a code isn't handsome, but it works like a charm! :) Thanks all for your helps.
这篇关于Mod重写斜线问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!