我的 php rooter 正在路由我的 css/jpg... 文件
My php rooter is routing my css/jpg... files
我有一个带有 htaccess 重写规则的自制 php rooter,但我的 public 文件总是在我离开登录页面后被 rooter 捕获,从而阻止了我其他页面上的这些源。
index.php rooter :
if(isset($_GET['url']) && !empty($_GET['url'])){
// Explosion of the URL
$url = explode('/', $_GET['url']);
$controllerName = "Controllers\".ucfirst(array_shift($url)).'Controller';
$methodName = strtolower(array_shift($url));
$param=strtolower(array_shift($url));
$controller = new $controllerName;
if($param!=null){
$controller->$methodName($param);
}
else{
$controller->$methodName();
}
}
else{
header("Location: Views/landing.php");
}
我的 htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [NC,L]
我应该更改 htaccess 吗?但是如何?
感谢
您的客户端资源应该这样引用:
<link href="/css/Dashboard/custom.css" type="text/css" rel="stylesheet" />
<link href="/images/favicon/favicon.ico" rel="icon" type="image/png" />
<script src="/bootstrap/dist/js/bootstrap.bundle.min.js" type="text/javascript"></script>
等因此,请注意 HTML 属性 href
和 src
中的前置斜杠字符 (/
)。它引用文档根目录的位置:/path/to/sample-mvc/public
.
举个例子:这是我基于 MVC 的应用程序的虚拟主机。也许有帮助。
<VirtualHost *:80>
ServerName local.myapp
DocumentRoot "/path/to/sample-mvc/public"
<Directory "/path/to/sample-mvc/public">
# For developing allow just the development machine
# (presuming that all dirs & files are inaccessible by default).
Require ip 127.0.0.1
# When Options is set to "off", then the RewriteRule directive is forbidden!
Options FollowSymLinks
# Activate rewriting engine.
RewriteEngine On
# Allow pin-pointing to index.php using RewriteRule.
RewriteBase /
# Rewrite url only if no physical folder name is given in url.
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite url only if no physical file name is given in url.
RewriteCond %{REQUEST_FILENAME} !-f
# Parse the request through index.php.
# Notice the absence of query string ("?url=...").
# I use "FastRoute" as router.
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
</VirtualHost>
我有一个带有 htaccess 重写规则的自制 php rooter,但我的 public 文件总是在我离开登录页面后被 rooter 捕获,从而阻止了我其他页面上的这些源。
index.php rooter :
if(isset($_GET['url']) && !empty($_GET['url'])){
// Explosion of the URL
$url = explode('/', $_GET['url']);
$controllerName = "Controllers\".ucfirst(array_shift($url)).'Controller';
$methodName = strtolower(array_shift($url));
$param=strtolower(array_shift($url));
$controller = new $controllerName;
if($param!=null){
$controller->$methodName($param);
}
else{
$controller->$methodName();
}
}
else{
header("Location: Views/landing.php");
}
我的 htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [NC,L]
我应该更改 htaccess 吗?但是如何?
感谢
您的客户端资源应该这样引用:
<link href="/css/Dashboard/custom.css" type="text/css" rel="stylesheet" />
<link href="/images/favicon/favicon.ico" rel="icon" type="image/png" />
<script src="/bootstrap/dist/js/bootstrap.bundle.min.js" type="text/javascript"></script>
等因此,请注意 HTML 属性 href
和 src
中的前置斜杠字符 (/
)。它引用文档根目录的位置:/path/to/sample-mvc/public
.
举个例子:这是我基于 MVC 的应用程序的虚拟主机。也许有帮助。
<VirtualHost *:80>
ServerName local.myapp
DocumentRoot "/path/to/sample-mvc/public"
<Directory "/path/to/sample-mvc/public">
# For developing allow just the development machine
# (presuming that all dirs & files are inaccessible by default).
Require ip 127.0.0.1
# When Options is set to "off", then the RewriteRule directive is forbidden!
Options FollowSymLinks
# Activate rewriting engine.
RewriteEngine On
# Allow pin-pointing to index.php using RewriteRule.
RewriteBase /
# Rewrite url only if no physical folder name is given in url.
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite url only if no physical file name is given in url.
RewriteCond %{REQUEST_FILENAME} !-f
# Parse the request through index.php.
# Notice the absence of query string ("?url=...").
# I use "FastRoute" as router.
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
</VirtualHost>