[英]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.