我怎么能改写URL重写的Apache2
anyhost.com/argument1/parameter2/some-text/
为
anyhost.com/index.php?path=argument1/parameter2/some-text/
或
anyhost.com/index.php?page=argument1&subpage=parameter2&subsubpage=some-text
或类似的东西?
我怎么能改写URL重写的Apache2
anyhost.com/argument1/parameter2/some-text/
为
anyhost.com/index.php?path=argument1/parameter2/some-text/
或
anyhost.com/index.php?page=argument1&subpage=parameter2&subsubpage=some-text
或类似的东西?
这应做到:
RewriteEngine On
# First example
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]
# Second example
RewriteRule ^(.*)/(.*)/(.*)$ index.php?page=$1&subpage=$2&subsubpage=$3 [L,QSA]
的QSA flag对任何查询字符串从原来的URL发送到index.php文件的查询字符串自动追加;如果您不需要该功能,则可以将其删除。
唉,我的第一条规则正是我想要的。非常感谢! – 2011-12-30 16:15:03
RewriteRule (.*)?/ index.php?path=$1
这是第一个版本。
RewriteRule (.*)/(.*)/(.*)?/ index.php?page=$1&subpage=$2&subsubpage=$3
这是第二个。您始终可以使用this tool来测试您的重写。
你有什么试过?此外,为了搜索引擎优化等目的,我认为你可能会看到这个倒退。 – ziesemer 2011-12-30 16:00:20