如何更改页面网址?

发布于 2025-01-01 13:39:54 字数 207 浏览 2 评论 0原文

如何获取页面url,然后根据地址栏中的查询结果重命名url?

抱歉,描述很简短。

我如何更改页面网址(使用 exmple.php?id=2 页面,但网址只是名称 www.something.org/zzz< /code> 其中 zzz 是与 id 关联的名称值,没有任何扩展名,扩展名将根据查询而改变)?

How to get page url and then rename the url based on query result at a time in the address bar ?

sorry for short description..

How can I change page url (working with a exmple.php?id=2 page but the url would be only the name www.something.org/zzz where zzz is the value of name associated with id without any extension that will change based upon query) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伤感在游骋 2025-01-08 13:39:54

查看 php 文档中的 $_SERVER['REQUEST_URI']header("Location : ")

Look at php docs for $_SERVER['REQUEST_URI'] and header("Location : ").

雨后彩虹 2025-01-08 13:39:54

我真的不确定你要什么,

但如果你想获取你所在页面的 URL:

$_SERVER['REQUEST_URI']

或者如果你谈到从查询字符串中获取某些内容,你会使用:

$_GET['page'] 

Page 是页面的查询字符串。 php?page=this_page

I'm really not sure what your asking for,

but if you want to get the the URL of the page you are on:

$_SERVER['REQUEST_URI']

Or if your speaking about getting something from the query string you would use:

$_GET['page'] 

Page being the query string of page.php?page=this_page

尤怨 2025-01-08 13:39:54

听起来您正在寻找类似 mod_rewrite 的东西。

这是一个更容易阅读的解释: http://corz.org/serv/tricks/htaccess2.php


EDIT

我认为你需要这样的东西:

example.php:

<?php
    if (!$_GET["name"] && $_GET["id"])
    {
        // perform MySQL query to get name based on id

        header("Location: http://www.something.org/zzz");
        die();   // stop execution of this page
    }

    // if we got here, $_GET["name"] is set, so do whatever this script is supposed to do.
?>

.htaccess: *参见下面的注释

Options +FollowSymLinks
RewriteEngine On

# the following rule will change the URL http://www.something.org/example.php?name=zzz to http://www.something.org/zzz
RewriteRule ^(^example.php?name=(.*)) example.php?name=$1 [NC]

注意: 上面的 .htaccess 示例未经测试,并且有一个很好的它有可能无法正常工作,但希望这会有所帮助,并且您可以弄清楚如何调整它以执行您想要的操作。

Sounds like you are looking for something like mod_rewrite.

Here is an easier to read explanation: http://corz.org/serv/tricks/htaccess2.php


EDIT

I think you will need something like this:

example.php:

<?php
    if (!$_GET["name"] && $_GET["id"])
    {
        // perform MySQL query to get name based on id

        header("Location: http://www.something.org/zzz");
        die();   // stop execution of this page
    }

    // if we got here, $_GET["name"] is set, so do whatever this script is supposed to do.
?>

.htaccess: *see note below

Options +FollowSymLinks
RewriteEngine On

# the following rule will change the URL http://www.something.org/example.php?name=zzz to http://www.something.org/zzz
RewriteRule ^(^example.php?name=(.*)) example.php?name=$1 [NC]

NOTE: The above .htaccess example is NOT tested, and there is a good chance that it doesn't work correctly as it is, but hopefully this helps and you can figure out how to adjust it to do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文