如何将请求重定向到网站上的“公共”带有Apache2的文件夹?

发布于 2025-02-11 21:48:02 字数 1648 浏览 0 评论 0原文

我的网站位于/var/www/html/qwerty/public文件夹中。我需要在root地址localhost/qwerty上的请求,以打开具有相同地址的网站的主页。也就是说,/var/www/html/qwerty/public/index.php应该打开,并且还可以通过适当的请求打开静态文件。例如,请求localhost/qwerty/123.jpg应打开/var/www/html/qwerty/public/public/123.jpg file。并且仍然在地址行中,应该有相同的地址(localhost/qwerty/123.jpg),而不包括public文件夹。

目前,当请求localhost/qwerty时,显示了文件夹的结构。按下public文件夹时,主页打开,localhost/qwerty/public在地址行上。

我需要打开的主页。此外,应禁止访问/var/www/www/html/qwerty文件夹,并在此处找到核心文件。

我阅读了有关此主题的几篇文章,并进行了设置,但它打开了文件夹树而不是主页。这是我配置Apache2服务器的第一天。 文件夹和文件的结构如下:

|--/var/www/html
|  |--index.html
|  |--qwerty
|  |  |--.htaccess
|  |  |--public
|  |  |  |--index.php

/var/www/html/qwerty/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

/etc/apache2/sites-sites-available/qwerty.cwerty.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/qwerty/public
    ServerName qwerty

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

:还使用了以下命令:

sudo systemctl restart apache2
sudo a2ensite qwerty

感谢您的关注。

My site is located to the /var/www/html/qwerty/public folder. I need the request at the root address localhost/qwerty to open the main page of the site with the same address. That is, the /var/www/html/qwerty/public/index.php file should open, and static files are also opened by appropriate requests. For example, the request localhost/qwerty/123.jpg should open the /var/www/html/qwerty/public/123.jpg file. And still in the address line there should be the same address (localhost/qwerty/123.jpg), without including the public folder.

At this time, when requesting localhost/qwerty, the structure of folders is displayed. When pressing the public folder, the main page opens, and localhost/qwerty/public on the address line.

enter image description here

I need the main page to open. In addition, access to the /var/www/html/qwerty folder should be forbidden, where the core files will be located.

I read several posts on this topic, and made the settings, but it opens the folder tree instead of the main page. This is my first day of work with configuring the apache2 server.
The structure of folders and files is as follows:

|--/var/www/html
|  |--index.html
|  |--qwerty
|  |  |--.htaccess
|  |  |--public
|  |  |  |--index.php

/var/www/html/qwerty/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

/etc/apache2/sites-available/qwerty.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/qwerty/public
    ServerName qwerty

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The following commands were also used:

sudo systemctl restart apache2
sudo a2ensite qwerty

Thanks for your attention.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文