英文:
XAMPP website can access the website other page but not on apache2
问题
在使用 PHP 7.4.32 Ubuntu 22.04 时遇到了问题。网站在 XAMPP 上的 Linux 和 Windows 上都进行了测试。打开网站的第一页会要求用户在 localhost/
输入用户名和密码,然后会重定向到 localhost/login
。在 Apache2 Webserve 上测试会导致在 localhost/login
上显示 404 未找到页面。于是我尝试在浏览器中打开页面文件夹 localhost/app/views/partials/
,结果显示真实网站布局的 404 未找到页面。在日志中找不到任何错误。
以下是我的 Config.php,其中定义了文件夹:
// 应用程序资源访问状态
define("AUTHORIZED", 200);
define("UNAUTHORIZED", 401);
define("NOROLE", 404);
define("FORBIDDEN", 403);
// 应用程序文件和目录
define("IMG_DIR", "assets/images/");
define("FONTS_DIR", "assets/fonts/");
define("SITE_FAVICON", IMG_DIR . "favicon.jpg");
define("SITE_LOGO", IMG_DIR . "logo.jpg");
define("CSS_DIR", SITE_ADDR . "assets/css/");
define("JS_DIR", SITE_ADDR . "assets/js/");
define("APP_DIR", "app/");
define("SYSTEM_DIR", "system/");
define("HELPERS_DIR", "helpers/");
define("LIBS_DIR", "libs/");
define("LANGS_DIR", "languages/");
define("MODELS_DIR", APP_DIR . "models/");
define("CONTROLLERS_DIR", APP_DIR . "controllers/");
define("VIEWS_DIR", APP_DIR . "views/");
define("LAYOUTS_DIR", VIEWS_DIR . "layouts/");
define("PAGES_DIR", VIEWS_DIR . "partials/");
define("AUDIT_LOGS_DIR", "logs/");
以下是我的 .htaccess:
RewriteEngine on
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request_uri=$1 [NC,L,QSA,B]
以下是我的 website.conf:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/website
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
为什么在打开 localhost/login
时会显示 404 未找到页面?它只在 XAMPP 的 Windows 和 XAMPP 的 Linux 上工作,而在 Apache2 Webserver 上不起作用。
如果内容太长,很抱歉,我是新手。
已经尝试更改 .htaccess 和权限,但问题仍然存在。
英文:
Using PHP 7.4.32 Ubuntu 22.04. I Got Website that has already tested on XAMPP both on Linux and windows. There's the first page we open are asking the user to put the id and password on localhost/
and it will be directed on localhost/login
. Testing on Apache2 Webserve will result page 404 not found on localhost/login
. So I tried to open where the page folder are on browser localhost/app/views/partials/
where the result is showing 404 not found with the real website layout.
Couldn't find any error in logs
Here's my Config.php where it define the folder
//Application resource access status
define("AUTHORIZED", 200);
define("UNAUTHORIZED", 401);
define("NOROLE", 404);
define("FORBIDDEN", 403);
// Application Files and Directories
define("IMG_DIR", "assets/images/");
define("FONTS_DIR", "assets/fonts/");
define("SITE_FAVICON", IMG_DIR . "favicon.jpg");
define("SITE_LOGO", IMG_DIR . "logo.jpg");
define("CSS_DIR", SITE_ADDR . "assets/css/");
define("JS_DIR", SITE_ADDR . "assets/js/");
define("APP_DIR", "app/");
define("SYSTEM_DIR", "system/");
define("HELPERS_DIR", "helpers/");
define("LIBS_DIR", "libs/");
define("LANGS_DIR", "languages/");
define("MODELS_DIR", APP_DIR . "models/");
define("CONTROLLERS_DIR", APP_DIR . "controllers/");
define("VIEWS_DIR", APP_DIR . "views/");
define("LAYOUTS_DIR", VIEWS_DIR . "layouts/");
define("PAGES_DIR", VIEWS_DIR . "partials/");
define("AUDIT_LOGS_DIR", "logs/");
here's my .htaccess
RewriteEngine on
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request_uri=$1 [NC,L,QSA,B]
here's my website.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/website
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Why does the website give 404 not found when open localhost/login
? It only works on Xampp windows and Xampp Linux not in the apache2 webserver.
Sorry if this is too long, I'm new on this.
Already tried to change the .htaccess and permission but still the same
答案1
得分: 1
在Ubuntu上,直接运行Apache2时,你可能会遇到一个AllowOverride问题,导致你的整个.htaccess文件未被读取。另一个可能性是你的重写引擎可能被禁用了。尝试将AllowOverride All
放入你的website.conf文件中,然后重新启动apache2:sudo service apache2 reload
。你可能还需要启用重写模块:sudo a2enmod rewrite
,然后sudo service apache2 reload
。
英文:
On Ubuntu, running Apache2 directly, you may be running into an AllowOverride issue where your entire .htaccess file is not being read. Another possibility is your rewrite engine may be disabled. Try placing AllowOverride All
into your website.conf file, then restart apache2: sudo service apache2 reload
. You might also need to enable the rewrite module: sudo a2enmod rewrite
then sudo service apache2 reload
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论