【问题标题】:htaccess for symfony2 in shared hosting共享主机中 symfony2 的 htaccess
【发布时间】:2013-06-13 02:26:45
【问题描述】:

我有一个共享主机。 我想在 public_html 文件夹中查看 .htaccess 文件的示例来设置 symfony2 应用程序(入口点是 web/app.php) 提前非常感谢

【问题讨论】:

标签: apache .htaccess symfony


【解决方案1】:

symfony 标准版已经包含了一个.htaccess,你可以使用它。

DirectoryIndex app.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

【讨论】:

  • 但这是 web 文件夹中的 .htaccess,我需要一个 .htaccess 放在 public_html 目录中,symfony2 项目将在该目录中
【解决方案2】:

试试这个:

DirectoryIndex public_html/app.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} !^/public_html/
    RewriteRule (.*) /public_html/$1
</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 302 ^/$ /public_html/app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

在根文件夹上设置它,比public_html高一级。

【讨论】:

    猜你喜欢
    • 2011-12-05
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    相关资源
    最近更新 更多