2012-02-10 60 views
2

我有一些網址,像這樣的:htaccess的mod_rewrite的部分GET變量

  • http://plutov.by/post/cubique_zf_jquery
  • http://plutov.by/post/mysql_useful_queries

我怎麼能與Apache的mod_rewrite的幫助下打開下一個頁面?

  • http://plutov.by/post/main?title=cubique_zf_jquery
  • http://plutov.by/post/main?title=mysql_useful_queries

此外,將與 「一個入口點改寫」 這一新的重寫規則的工作?

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . index.php [L] 

謝謝。

回答

3

爲了使新的重寫規則的路徑一些修改可能需要以「一個入口點重寫」工作,有你rewriteRules這樣的:

QSA標誌是強制性要添加一個新的查詢字符串。

RewriteEngine On 

RewriteRule ^(post)/([\w\d\-]+)/?$ $1/main?title=$2 [QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule . index.php [L] 
+0

如果您不關心現有查詢字符串,則QSA標記不是必需的。 – ADTC 2016-12-11 08:47:58

3

您可以使用這樣的事情在你的.htaccess:

RewriteRule ^post/(.*)$ post/main?title=$1 [L] 

您應該保持此規則之前一個入口點重寫規則。如果規則將觸發然後重寫規則查找將結束(因爲指定[L]選項)

,如果你想使用虛擬主機而言,這些規則