我想知道 CodeIgniter 如何重写 url。默认情况下,没有 htaccess 文件,但它仍然有效吗?
谢谢
已经有一段时间了,但如果您不知道 .htaccess 是一个隐藏文件,它位于您的根文件夹中...希望对您有所帮助
一切都通过 index.php 路由。IE
site.com/index.php/controller/method/arg
您将使用 htaccess 文件删除 URL 的“index.php”部分。IE
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/tmp|/robots\.txt|/crossdomain\.xml|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
这会给你“更漂亮”的网址,即
site.com/controller/method/arg
但是,这不是 CI 正确路由 URL 所必需的。根据您的 apache conf,这通常仍会正确解析,并将请求移交给 index.php,这反过来将“路径”确定为 /controller/method/arg。