Хорошо, я исправил всю проблему, настроил сервер на localhost, но я хочу скрыть каталог / public и отображать содержимое в корневой папке моего документа, например /forum/, и для регистрации /forum/login вместо перехода на forum/public/login. Вот файл htaccess, но он не работает, потому что дает No routes for GET /forum/.
RewriteEngine On
RewriteBase /forum/
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
Что я делаю не так?
Мне нужен htacces, потому что я не хочу получать доступ к общедоступному каталогу, я хочу, чтобы контент отображался в корневом каталоге проекта, а не внутри публично.
Все это можно настроить в маршрутизации Symfony.
Нет, я пробовал использовать / forum / index и т. д. В маршрутизации, и это дает то же самое. Пробовал также с очисткой кеша, и снова я получил ошибку маршрута.
Я исправил это, изменив общедоступные каталоги и переместившись в htdocs на локальном хосте. Затем отредактировал index.php и указал правильный путь к ENV и автозагрузке поставщика.
.. немного в сторону .. почему вы хотите заблокировать директорию паба? что ты там хранишь ?!






На самом деле иногда нам может потребоваться добавить файл .htaccess
Мы можем использовать этот код как файл .htaccess. Я проверил это на Ubuntu VPS, а также на Cpanel.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
Мой корневой файл .htaccess выглядит так, я думаю, вы можете поместить его в корневую папку Symfony.
# Removes index.php from ExpressionEngine URLs
RewriteEngine on
# RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*) /public/$1 [L]
Затем мой .htaccess внутри папки public/:
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} = ""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
# Rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
Вы проверяли документацию по маршрутизации Symfony? Вам не обязательно использовать htaccess symfony.com/doc/current/routing.html