Php 避免Apache别名路径包含CSS等HTML资源的一种方法
这里有一个问题,因为我目前的解决方案并不能真正满足我对以下问题的需求: 我有一个自己的PHP框架,开发中使用MVC模式。我的路由器工作得很完美,但我有一个问题我找不到解决方案 我将每个传入的请求路由到index.php文件,该文件位于我的框架的基本路径中。当然,在包含css时使用相对路径并没有问题,例如:Php 避免Apache别名路径包含CSS等HTML资源的一种方法,php,html,apache,mod-rewrite,Php,Html,Apache,Mod Rewrite,这里有一个问题,因为我目前的解决方案并不能真正满足我对以下问题的需求: 我有一个自己的PHP框架,开发中使用MVC模式。我的路由器工作得很完美,但我有一个问题我找不到解决方案 我将每个传入的请求路由到index.php文件,该文件位于我的框架的基本路径中。当然,在包含css时使用相对路径并没有问题,例如: <link rel="stylesheet" type="text/css" href="style/include/css/style.css" /> 提前感谢您的帮助~对于h
<link rel="stylesheet" type="text/css" href="style/include/css/style.css" />
提前感谢您的帮助~对于html链接(css、javascript、图像等),您必须使用绝对路径而不是相对路径 例如:
<link rel="stylesheet" type="text/css" href="/style/include/css/style.css" />
或(两者相同)
哈哈,这太简单了…多谢了,这真是太有魅力了!
<link rel="stylesheet" type="text/css" href="<?=Router::getInstance()->getSubdirectoryPrefix()?>style/include/css/style.css" />
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
<link rel="stylesheet" type="text/css" href="/style/include/css/style.css" />
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /index.php [L]
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]