简体   繁体   English

如何将www.mysymfonypage.com/public更改为www.mysymfonypage.com?

[英]How can I change www.mysymfonypage.com/public to www.mysymfonypage.com?

When I locally open the url localhost:8000 then I see my main homepage. 当我在本地打开url localhost:8000我会看到我的主页。

I installed the apache pack (composer require symfony/apache-pack) and uploaded everything via ftp on my server. 我安装了apache包(composer需要symfony / apache-pack),并通过ftp将所有内容上传到我的服务器上。

This is the .htaccess file in my public folder: 这是我的公用文件夹中的.htaccess文件:

# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 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}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # Sets the HTTP_AUTHORIZATION header removed by Apache
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # 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.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the start page to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 307 ^/$ /index.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

I open www.mysymfonypage.com and it redirects to the public folder, which is fine. 我打开www.mysymfonypage.com ,它将重定向到公用文件夹,这很好。 But my URL is now www.mysymfonypage.com/public 但是我的网址现在是www.mysymfonypage.com/public

How can I change this? 我该如何更改?

Really you should reconfigure your webserver to use /public as webroot - How do I change the root directory of an apache server? 确实,您应该重新配置Web服务器以将/public用作Webroot- 如何更改apache服务器的根目录?

Alternatively you could add 或者,您可以添加

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

after RewriteEngine On - BUT this will 301 redirect all your requests so that would likely cause issues / undesired behaviour somewhere along the line. RewriteEngine On后-但是,这将重定向301您的所有请求,这样很可能会导致问题/意外行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (符号4)如何从非控制器类中获取项目的基本URI(http://www.yourwebsite.com/)? - (Symfony 4) How can I get the base URI of my project (the http://www.yourwebsite.com/) from within a non-controller class? www.example.com和example.com中的Symfony会话 - Symfony sessions in www.example.com and example.com 无法连接到www.googleapis.com端口443:网络无法访问 - Failed to connect to www.googleapis.com port 443: Network unreachable 如何在symfony2中添加自定义配置,例如host_name =“ www.abc.com”? - how to add custom configuration e.g. host_name = “www.abc.com” in symfony2? PHP致命错误:在第47行的/var/www/znata.com/app/AppKernel.php中找不到类&#39;Application \\ Sonata \\ MediaBundle \\ ApplicationSonataMediaBundle&#39; - PHP Fatal error: Class 'Application\Sonata\MediaBundle\ApplicationSonataMediaBundle' not found in /var/www/znata.com/app/AppKernel.php on line 47 如何在symfony 4上强制使用https和www - How to force https and www on symfony 4 如何启用诸如site.mydomain.com之类的网址? - How can I enabled urls like site.mydomain.com? htcaccess和symfony 2重定向非www-&gt; www - htcaccess and symfony 2 redirect non www -> www 我无法缓存:清除,因为www数据使用了var / cache / dev / profiler - i can't cache:clear because var/cache/dev/profiler is used by www-data 重定向到.htaccess中的https:// www时如何排除某些URL - How to make an exclusion for some url when redirectiong to https://www in .htaccess
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM