2011-12-30 46 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來測試您的重寫。