XAMPP 网站可以访问其他页面,但无法访问 apache2 页面。

huangapple go评论63阅读模式
英文:

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(&quot;AUTHORIZED&quot;, 200);
define(&quot;UNAUTHORIZED&quot;, 401);
define(&quot;NOROLE&quot;, 404);
define(&quot;FORBIDDEN&quot;, 403);

// Application Files and Directories 
define(&quot;IMG_DIR&quot;,  &quot;assets/images/&quot;);
define(&quot;FONTS_DIR&quot;,  &quot;assets/fonts/&quot;);
define(&quot;SITE_FAVICON&quot;, IMG_DIR . &quot;favicon.jpg&quot;);
define(&quot;SITE_LOGO&quot;, IMG_DIR . &quot;logo.jpg&quot;);

define(&quot;CSS_DIR&quot;, SITE_ADDR . &quot;assets/css/&quot;);
define(&quot;JS_DIR&quot;, SITE_ADDR . &quot;assets/js/&quot;);
define(&quot;APP_DIR&quot;, &quot;app/&quot;);
define(&quot;SYSTEM_DIR&quot;, &quot;system/&quot;);
define(&quot;HELPERS_DIR&quot;, &quot;helpers/&quot;);
define(&quot;LIBS_DIR&quot;, &quot;libs/&quot;);
define(&quot;LANGS_DIR&quot;, &quot;languages/&quot;);
define(&quot;MODELS_DIR&quot;, APP_DIR . &quot;models/&quot;);
define(&quot;CONTROLLERS_DIR&quot;, APP_DIR . &quot;controllers/&quot;);
define(&quot;VIEWS_DIR&quot;, APP_DIR . &quot;views/&quot;);
define(&quot;LAYOUTS_DIR&quot;, VIEWS_DIR . &quot;layouts/&quot;);
define(&quot;PAGES_DIR&quot;, VIEWS_DIR . &quot;partials/&quot;);
define(&quot;AUDIT_LOGS_DIR&quot;, &quot;logs/&quot;);

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

&lt;VirtualHost *:80&gt;
	ServerName localhost
	ServerAlias localhost
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/website
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
&lt;/VirtualHost&gt;

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

huangapple
  • 本文由 发表于 2023年3月12日 14:35:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711449.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定