[英]slim framework htaccess 404 not found
我知道有很多这样的问题,我都尝试过,但似乎没有一个起作用。
用户目录已配置,因此我可以打开localhost/~h22
(h22是用户名)
http://localhost/~h22/slim/index.php/hello/Megh可以工作,但是http:// localhost /〜h22 / slim / hello / Megh不能工作,提示404错误
浏览器中的确切错误
Not Found
The requested URL /home/h22/public_html/slim/index.php was not found on this server.
.htaccess
文件被解析为在文件中写入乱码,从而导致内部服务器错误。
我的代码位于
/home/h22/public_html/slim
├── composer.json
├── composer.lock
├── .htaccess
├── index.php
└── vendor
...
index.php :
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, " . $name;
});
$app->run();
?>
.htaccess :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
/etc/httpd/conf.d/slim.conf :
<Directory "/home/h22/public_html/slim">
AllowOverride All
Require all granted
</Directory>
好吧,我解决了这个问题。
在这里您需要添加行
RewriteBase /~h22/slim/
在RewriteEngine On
因此,在任何其他项目中,如果您的URL是localhost/abcd
,则需要编写RewriteBase /abcd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.