我希望有这些漂亮的网址:
- 所有类别概述:本地主机/类别
- 创建新类别的表单:本地主机/类别/新建 要编辑类别
- 的表单:本地主机/类别/编辑/4
由于我正在控制器中使用命令模式,因此我的进程中有这些操作在我的控制器中请求我有这些丑陋的 URL:
- 本地主机/索引.php?操作=类别概述
- localhost/index.php?action=categoryNew
- localhost/index.php?action=categoryNew&id=4
我正在尝试使用 .htaccess 这个
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z]+)/([0-9]*) index.php?action=$1&id=$2
但这不起作用+我的CSS没有加载。我试过这些:
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap.css/">
<link rel="stylesheet" href="/css/bootstrap.css/">
你能帮我怎么做吗
- 这些漂亮的网址是否正确完成?
- 让 CSS 出现?
尝试使用以下条件:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
而不是
RewriteCond %{REQUEST_FILENAME} !-f
因此,apache 在将 url 传递给控制器之前,会尝试查找目录 (-d) 和符号链接 (-l)。