2013-12-18 59 views
-3
example.com/index.php?route=pavblog/blogs&id=$2 

2个参数我需要这个网址加载到重写URL与htaccess的

example.com/blogs/blogname 

我在.htaccess试过这样:

RewriteRule ^blogs/(.*) index.php?route=pavblog/blogs&id=$2 

,但它不工作。

+1

为什么在2美元?为什么不是1美元? –

回答

0

我想您是这样的:

RewriteRule ^blogs/(.*) index.php?route=pavblog%2Fblogs&id=$1 

我改变$2$1(只有一个捕获组),我躲过了/%2F

+0

嗨Dystroy, 非常感谢你的回答, 但我需要加载此网址 example.com/index.php?route=pavblog/blogs 是这样 example.com/blogs/ 这个网址 example.com/index.php?route=pavblog/blogs&id=13 是这样 example.com/blogs/blogname – Raja

+0

尝试'/ index.php'而不仅仅是'的index.php '。有时候这有帮助。另外,如果您在原始传入URI中有任何查询字符串值,您需要一个[QSA]标志来保存它们。最重要的是,让你的术语保持直线:你的传入URI(来自外部世界)的URI是/ blogs/blogname,并且你将它转换成服务器和PHP可以理解的形式:/index.php?....现在,如果博客ID可以为空(空),你想要发生什么? –

+0

你想如何处理/ blogs /,在第二种情况下,你不能这么做 - 它无法从传入的URI中获取id。所有可用来从另一个博客告诉一个博客是博客名称。如果博客名称包含该ID(例如,“myblog-13”或“13/myblog”),那将是可能的。 –