如何将请求重定向到网站上的“公共”带有Apache2的文件夹?
我的网站位于/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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论