modrewrite php 查询字符串
我想改变:
进入
http://example.com/en/blog.html
或只是
http://example.com/blog.html
I would like to change:
into just
http:// example.com/en/blog.html
or just
http:// example.com/blog.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在尝试实现更友好的网址,因此我假设您希望在内部将
http://example.com/en/blog.html
重写为http://example.com/index.php?p=blog&pid=2&lid=1&l=en
。我推荐的最实用的方法是将所有内容重写到 PHP 脚本中,并在 PHP 内部进行重写。这样您的 PHP 应用程序就可以完全控制 URI。
在 PHP 中,您可以通过超全局变量访问原始 URI:
$_SERVER[ "REQUEST_URI" ]
。注意:一定要消毒,一定要消毒,一定要消毒!编辑
如果您想通过
.htaccess
完成整个操作,请参阅下面的示例。但请注意,如果您将来要扩展 URI 结构(即通过添加新规则),那么与在 PHP 应用程序中执行此方法相比,这种方法可能会变得更难以维护。编辑#2:在所有三个规则中添加了缺少的
^
字符,即更改了([\/]*)
到([^\/]*)
I think that you are trying to achieve more friendly URLs, so I'm assuming that wan to internally rewrite
http://example.com/en/blog.html
tohttp://example.com/index.php?p=blog&pid=2&lid=1&l=en
.The most practical way that I can recommend is to rewrite everything to your PHP script, and do the rewriting internally in PHP. That way your PHP application can have full control over URIs.
In PHP, you can then access the original URI via superglobals:
$_SERVER[ "REQUEST_URI" ]
. Note: sanitize, sanitize, sanitize!Edit
If you want to do the whole thing via
.htaccess
, then see the example below. Note however that if you'll expand your URI structure in the future (i.e. by adding new rules), then this approach might become more difficult to maintain as opposed to doing it within your PHP application.Edit #2: added a missing
^
character in all three rules, i.e. changed([\/]*)
to([^\/]*)