簡體   English   中英

重新寫入規則不起作用並導致CSS錯誤

[英]ReWrite Rule Not Working & Causing CSS Errors

我想通過.htaccess使用RewriteRule,但我遇到了一些問題。 我已經使用以下方法測試了該規則:

RewriteRule ^newpage articles.php [NC,L]

而當我訪問blog.local.com/newpage即時顯示articles.php ,所以我知道我的htaccess工作正常。

但是,當我使用:

DirectoryIndex articles.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^articles/([0-9a-zA-Z_-]+)/([0-9]+) articles.php?cat=$1&currentpage=$2 [NC,L]

並訪問blog.local.com/articles/all/2 ,顯示了第一篇文章頁面,但該頁面沒有任何CSS樣式。 誰能幫我這個忙嗎?

您需要關閉MultiViews選項。

Options -MultiViews
DirectoryIndex articles.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^articles/([\w-]+)/([0-9]+)/?$ articles.php?cat=$1&currentpage=$2 [NC,L,QSA]

Apache's content negotiation module使用Option MultiViews ,該Apache's content negotiation module mod_rewrite 之前運行,並使Apache服務器匹配文件擴展名。 因此/file可以位於URL中,但它將提供/file.php

同樣,為了解決css / js問題,您可以在頁面HTML的<head>部分下面添加此代碼:

<base href="/" />

這樣就可以從該基本URL而不是當前頁面的URL解析每個相對 URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM