2011-12-30 70 views
2

我怎么能改写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

或类似的东西?

+0

你有什么试过?此外,为了搜索引擎优化等目的,我认为你可能会看到这个倒退。 – ziesemer 2011-12-30 16:00:20

回答

1

这应做到:

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文件的查询字符串自动追加;如果您不需要该功能,则可以将其删除。

+0

唉,我的第一条规则正是我想要的。非常感谢! – 2011-12-30 16:15:03

1
RewriteRule (.*)?/ index.php?path=$1 

这是第一个版本。

RewriteRule (.*)/(.*)/(.*)?/ index.php?page=$1&subpage=$2&subsubpage=$3 

这是第二个。您始终可以使用this tool来测试您的重写。