【问题标题】:css and image conflicts on. htaccess rewriterule [closed]css和图像冲突。 htaccess重写[关闭]
【发布时间】:2013-05-14 15:07:32
【问题描述】:

我看到了许多与我遇到的问题类似的问题,但我已经遵循了我从中获得的所有解决方案,而且似乎我无法让它在没有冲突的情况下运行。

HTML CSS 调用:

<head>
<base href="http://localhost/smartwavedev.sw_apiwebtool/" />
<link rel="stylesheet" href="assets/css/main.css" type="text/css">
<link rel="stylesheet" href="assets/css/login.css" type="text/css">
<link rel="stylesheet" href="assets/css/dashboard.css" type="text/css">
<link rel="stylesheet" href="assets/css/bootstrap/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="assets/css/docs.css" type="text/css">
</head>

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php
RewriteRule ^([^/]+)/([^/]+)$ $1.php?page=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ $1.php?page=$2&nav=$3

感谢您的帮助!

【问题讨论】:

  • 你忘了问问题。 “没有冲突就无法运行”不是一个问题 - 什么冲突,出了什么问题,你怀疑问题是什么?
  • 无法访问css和图片文件。

标签: php .htaccess


【解决方案1】:

首先这个条件是错误的:

RewriteCond %{REQUEST_FILENAME}\.php -f

应该是:

RewriteCond %{REQUEST_FILENAME} !-f

现在它将在所有文件上触发。接下来,RewriteCond 将只匹配 first RewriteRule 跟随它。因此,具有 3 个元素的第三条规则仍然匹配(并因此阻止)您的 CSS 文件。您要么需要为所有规则重复 RewriteCond 行,要么实施更好的解决方案。对于您的具体情况,我真的建议放弃重写的整个概念并将其替换为:

 FallbackResource index.php

然后在index.php文件中解析$_SERVER['REQUEST_URI']

【讨论】:

  • 谢谢。我通过在所有规则之前重复 rewritecond 来解决它。
猜你喜欢
  • 1970-01-01
  • 2012-06-09
  • 2021-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多