我想使用它来访问我的一个控制器。 PHP扩展名,例如http://localhost/myproject/branding.php
在上述情况下,myproject是我的项目名称,branding是我的控制器名称。我可以访问http://localhost/myproject/branding,但是当我在控制器名称前添加.PHP扩展名时,它会抛出错误(找不到页面。)。
如何使用.htaccess解决此问题。
框架-Codeigniter
我正在使用.htaccess中的以下代码来隐藏index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
</IfModule>
无需使用.htaccess。您可以在application/config/config.php
文件中进行设置:
$config['url_suffix'] = '.php';
此选项允许您将后缀添加到由CodeIgniter。
例如:使用url-helper函数创建的链接
<?= anchor('myproject/branding');?>
将自动添加后缀.php