我可以重新写我的网址是这样,是一个好主意? [英] Can I re-write my URLs like this and is it a good idea?

查看:96
本文介绍了我可以重新写我的网址是这样,是一个好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能重新写(Apache的MOD-重写)从这个网址:

Is it possible to re-write (Apache Mod-Rewrite) a URL from this:

http://www.example.com/view.php?t=h5k6 以这种 http://www.example.com/h5k6

http://www.example.com/view.php?t=h5k6 to this http://www.example.com/h5k6

这样做的理由重新写的是URL需要很短的(有点像一个微小的URL服务)。

The reason for this re-write is that the URL needs to be very short (a bit like a tiny URL service).

但愿新的URL依旧打我view.php页面?难道能仍然使用超全局数组GET的( $ _ GET )来访问变量 T ?我还是希望我的index.php页面映射到这个 http://www.example.com

Would that new URL still hit my view.php page? Would it be able to still make use of the super global array GET ($_GET) to access the variable t? I still want my index.php page to map to this http://www.example.com.

我也有影响AP preciate评论这可能是我有点小白的。 :)

I would also appreciate comments on effects this may have as I am a bit of a noob. :)

感谢所有

推荐答案

mod-rewrite工作的其他方式。请求会来像这样 http://www.example.com/h5k6 ,将被改写为 http://www.example.com /view.php?t=h5k6 内部。这样,你的PHP脚本能够对请求做出响应,好像他们是被作为GET参数,但用户看到的网址,在一个更​​友好的方式。

The terminology of mod-rewrite works the other way. Requests would come in like this http://www.example.com/h5k6 and would be rewritten to http://www.example.com/view.php?t=h5k6 internally. That way your PHP scripts can respond to the requests as if they were sent as GET parameters, but users see the URLs in a much friendlier way.

所以,你不必改变任何PHP脚本,你仍然可以访问参数 T 从GET数组。

So you don't have to change any PHP scripts, and you can still access the parameter t from the GET array.

在你的情况,规则是这样的:

In your case, the rule would look like this:

RewriteRule ^/(.*) /view.php?t=$1

您可能想具体谈谈你接受什么样的(而不是仅仅是包罗万象的。* 前pression)。另外,如果你有超过view.php其他在此目录中的其他页面,你可能希望此规则的例外。

You might want to be more specific about what you accept (instead of just the catch-all .* expression). Also, you might want exceptions to this rule if you have other pages in this directory other than view.php.

这篇关于我可以重新写我的网址是这样,是一个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆