duanmaifu3428 2013-11-22 19:04
浏览 17
已采纳

我该如何重定向?

I have made a page where user can come and create a blog, an excerpt from creating a new blog page :-

<tr>
<td>Blog URL</td>
<td>www.foo.com/blogs/ <input type="text" name="ns"></td>
</tr>

Now, the user would enter something in that text box, suppose, the user enters foobar..then how can I make a setting a .htaccess so that the user can access that blog via www.foo.com/blogs/foobar instead of something www.foo.com/blogs.php?id=somethinghere ..

How can this be accomplished?

Thanks.

Update

Thanks @anubhava for that htaccess code, but it doesn't seems to be working correctly, here's what I have right now.

blogs.php

<?php
session_start();
include 'dbconnector.php';
include 'functions.php';
$owner=$_SESSION['username'];
$id=$_GET['id'];

$equery="select * from events where eventid = '" . $id . "'";
$resulte=mysql_query($resulte) or die (mysql_error($db));
$rowe=mysql_fetch_assoc($resulte);
if((isset($_SESSION['logged'])) && ($_SESSION['logged']==1))
{
?>

Name : <?php echo ($rowe['name']); ?>
Zipcode : <?php echo ($rowe['zipcode']); ?>
<?php
}
else
{
    header('Location:/login/');
    exit();
}
?>

This code should've plucked up records for a blog with id something and then rewrite the url to www.foo.com/blogs/namehere if I directly open up www.foo.com/blogs/namehere

namehere is the name which the user has entered while creating a blog, but the only error I get is a 404 page not found. Really confused here, please explain how this is going to work. Thanks.

  • 写回答

1条回答 默认 最新

  • duanbaque4230 2013-11-22 19:07
    关注

    Put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    RewriteBase /m/
    
    RewriteRule ^blogs/(.+)$ blogs.php?id=$1 [L,QSA] 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决