[英]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¤tpage=$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¤tpage=$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.