Apache modrewrite php查询字符串

Apache modrewrite php查询字符串,apache,mod-rewrite,Apache,Mod Rewrite,我想改变一下: 进入公正 http://example.com/en/blog.html 或者只是 http://example.com/blog.html 我认为您正在尝试实现更友好的URL,因此我假设wan需要在内部重写http://example.com/en/blog.html至http://example.com/index.php?p=blog&pid=2&lid=1&l=en 我可以推荐的最实用的方法是将所有内容重写到PHP脚本中,并在PHP内部进行重写。这样,PHP应用程序就可

我想改变一下:

进入公正

http://example.com/en/blog.html

或者只是

http://example.com/blog.html

我认为您正在尝试实现更友好的URL,因此我假设wan需要在内部重写
http://example.com/en/blog.html
http://example.com/index.php?p=blog&pid=2&lid=1&l=en

我可以推荐的最实用的方法是将所有内容重写到PHP脚本中,并在PHP内部进行重写。这样,PHP应用程序就可以完全控制URI

RewriteEngine On
RewriteBase /

RewriteRule .* index.php [L]
在PHP中,您可以通过superglobals访问原始URI:
$\u SERVER[“REQUEST\u URI”]
。注意:消毒,消毒,消毒


编辑

如果您想通过
.htaccess
完成整个过程,请参见下面的示例。但是请注意,如果将来要扩展URI结构(即通过添加新规则),那么与在PHP应用程序中进行维护相比,这种方法可能更难维护

RewriteEngine On
RewriteBase /

# http://example.com/en/blog.html
RewriteRule ^([^\/]*)/([^\/]*)\.html$ index.php?l=$1&p=$2 [NC,QSA,L]

# http://example.com/blog.html
RewriteRule ^([^\/]*)\.html$ index.php?p=$1 [NC,QSA,L]

# alternatively you can change the last line to add a default language (if not present)
RewriteRule ^([^\/]*)\.html$ index.php?l=sk&p=$1 [NC,QSA,L]

编辑#2:在所有三条规则中添加了一个缺少的
^
字符,即将
([\/]*)
更改为
([\/]*)

至。--我想是相反的。但我明白你的意思,我明白了。您正在尝试重写或重定向URL吗?我将后者理解为一种不破坏现有站点的传统链接的方法,同时尝试升级URI设计。如果是这样的话,那么您可以安全地使用上面的链接,因为原始链接(…/index.php?p=blog&…)仍然可以工作。我想您是对的,我已经用php重写了我的URL,使其更加灵活。谢谢!