简体   繁体   English

我将如何重定向呢?

[英]How would I redirect this?

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 .. 现在,用户将在该文本框中输入内容,假设用户输入foob​​ar ..那么我如何设置.htaccess,以便用户可以通过www.foo.com/blogs/foobar访问该博客,而不是一些www.foo.com/blogs.php?id=something此处..

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. 感谢@anubhava提供的htaccess代码,但它似乎无法正常运行,这就是我现在所拥有的。

blogs.php 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 如果我直接在此处打开www.foo.com/blogs/name,则此代码应该已提取ID为某事的博客的记录,然后将URL重写为www.foo.com/blogs/name。

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. namehere是用户在创建博客时输入的名称,但是唯一的错误是找不到404页面。 Really confused here, please explain how this is going to work. 在这里真的很困惑,请解释一下这是如何工作的。 Thanks. 谢谢。

Put this code in your DOCUMENT_ROOT/.htaccess file: 将此代码放在您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On
RewriteBase /m/

RewriteRule ^blogs/(.+)$ blogs.php?id=$1 [L,QSA] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM