問題描述
我正在嘗試創建一個 mod 重寫來簡單地打開這些鏈接:
I'm trying to create a mod rewrite to simply turn these links:
/index.php?page=home
/?page=home
進入
/home
有人可以告訴我這是怎么做的嗎?在我們討論這個主題時,是否有任何關于 mod 重寫的好資源可供閱讀?到目前為止,我最大的困難是我看不到任何調試它的方法.事情要么有效,要么無效.
Can someone show me how this is done? While we're on the subject, are there any good resources to read up on mod rewrite? My biggest struggle so far is that I don't see any way of debugging it; things either work or they don't.
推薦答案
有多種方法可以做到這一點.這個規則適用于任何不存在的文件:
There are a variety of ways to do this. This one applies the rule to any non-existent file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L]
您可能需要在頂部添加 RewriteEngine on
,這會在您的 Web 文檔根目錄中的 .htaccess
中添加.當然,所有這些都取決于您的 Web 主機是否允許使用 htaccess (mod_rewrite) 以及規則覆蓋文件是否應命名為 .htaccess.不過兩者都很常見,所以應該沒有問題.
You may have to add RewriteEngine on
at the top, and this goes in .htaccess
in your web document root. All of this, of course, depends on whether use of htaccess (mod_rewrite) is allowed by your web host and whether the rule override file should be named .htaccess. Both are pretty common though, so it shouldn't be a problem.
這篇關于簡單的 Mod 重寫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!