2010-12-13 52 views
-2

要轉發如下:如何爲這些情況編寫.htaccess mod_rewrite規則?

localhost/bla/index.html -> localhost/index.php?s=bla/index.html 
localhost/blub.html -> localhost/index.php?s=blub.html 
localhost/blog.html?site=10 -> localhost/index.php?s=blog.html&site=10 
localhost/folder -> localhost/index.php?s=folder 

但我只想做重定向.html和文件夾。

回答

2
RewriteCond %{REQUEST_URI} .html$ [OR] 
RewriteCond -d 
RewriteRule (.*) /index.php?s=$1 [L,QSA] 

只有當URI與名「.html」結尾,或者如果它是一個文件夾,它改寫了整個URI到?S =查詢字符串。 QSA標誌應該確保.html文件(?site = 10)上的查詢字符串也被添加到新的url中。

+0

非常好。謝謝。我怎樣才能使這與.html和.php也工作? – 2010-12-14 07:28:07

+0

你是什麼意思? – 2010-12-14 08:36:45

+0

如果我想使用.php和.html(localhost/bla.php - > localhost/index.php?s = bla.php – 2010-12-14 14:46:38