First ill解釋index.php如何在我的網站中工作。mod_rewrite衝突,兩個字符串和一個包含其他文件
首先,index.php具有過濾GET名稱的功能,如果不爲空,並且存在我的頁面的名稱(我定義的),比如博客,照片,模態,關於和聯繫等,包括具有請求的同名GET
我的htacess可以很好地處理單個頁面,比如模式,關於,聯繫,但是現在我想添加「子類別」,如博客/ hello-world。
blog.php的工作方式與索引相同,其中包含來自GET變量(post)的同名文件。
用別人的話說,讓我們看看在行動。
index.php頁面=方式? - > /模式
index.php頁面=博客&後= nameofpost - >我可以看到正確 但是當使用htaccess具有與第一條規則衝突,因爲它分析博客作爲單個文件,並沒有空間到另一個GET變量
我想重寫index.php?page = blog & post = nameofpost to/blog/nameofpost與第一條重寫規則沒有衝突。
重寫規則(。*)的index.php?PG = $ 1 [L]
如果我使用重寫規則,我不能用我的單頁等接觸的htacess多個字符串(的index.php?PG =接觸/ contact)它給我一個404錯誤。
我的index.php(結構)
$url = addslashes($_GET["pg"]);
if(isset($url) && ($url === "photos" || $url === "time" || $url === "modalities" || $url === "contact" || $url === "blog" || $url === "about")){
include "page/{$url}.php";
return $lock = true;
}elseif($url === "" || $url === "home" || !isset($url) || (empty($url) || trim($url)==='')){
include "home.php";
}else{
echo "Error 404";
}
.htaccess文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?pg=$1 [L]
ErrorDocument 404 /404
ErrorDocument 403 /404
ErrorDocument 404 /404
Options -Indexes
IndexIgnore *
我知道.htaccess文件未配置,因爲我無法找到解決的辦法做到這一點,兩點式在同一時間的網址。
非常感謝您的關注。
感謝,但不幹活g,當我在字符串的末尾使用斜線時,例如,mysite.com/about/它顯示內容(PHP),但它添加了我的html的雙重路徑,如style/style/site.css img/img/image01 .jpg如果我在同一時間使用第一個或第二個規則no,就像你告訴兩個重寫級別一樣。 RewriteRule([^ /] *)index.php?pg = $ 1 [L] 適用於單個頁面,例如模態,關於,聯繫... RewriteRule(。*)/(。*)index.php?pg = $ 1&post = $ 2 [L] 以及包含子頁面的頁面,如博客,新聞等... – Kauan
我無法在週末編輯此內容,所以我現在更新了答案 - 它應該(!!)如果你把兩條規則都放在你的工作中,你就會工作htaccess文件。它也應該適應尾隨的斜槓。 – icabod
很高興爲您提供意見,我們會測試。 – Kauan