使用 symfony 1.4 而不更改 apache 配置

发布于 2024-09-02 04:59:48 字数 397 浏览 2 评论 0原文

是否可以在不更改apache配置文件的情况下将/web目录设置为webroot?

我尝试使用以下 .htaccess 代码,但如果我转到 localhost/module/,它会显示 404 错误。但是如果我转到 localhost/web/module/ 那么一切都会正常。

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    sf/(.*) lib/vendor/symfony/data/web/sf/$1 [L]
   RewriteRule    ^$ web/    [L]
   RewriteRule    (.*) web/$1 [L]
</IfModule>

Is it possible to set the /web directory as webroot without changing apache configuration file?

I tried using the following .htaccess code, but if i go to localhost/module/, it displays 404 error. But if i go to localhost/web/module/ then everything works.

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    sf/(.*) lib/vendor/symfony/data/web/sf/$1 [L]
   RewriteRule    ^$ web/    [L]
   RewriteRule    (.*) web/$1 [L]
</IfModule>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

笑红尘 2024-09-09 04:59:48

我确实喜欢在根目录上这样做:

RewriteEngine On
RewriteBase /
RewriteRule (.*) ./web/$1 [L]

并编辑 web/.htaccess 取消注释“RewriteBase /”行。

这使得所有 mysite.com/aaaa/bbbb 都像 mysite.com/web/aaaa/bbbb 一样工作

i do like this on the root :

RewriteEngine On
RewriteBase /
RewriteRule (.*) ./web/$1 [L]

And edit web/.htaccess uncommented the 'RewriteBase /' line.

this make all the mysite.com/aaaa/bbbb works like mysite.com/web/aaaa/bbbb

無處可尋 2024-09-09 04:59:48

简短的回答:不。

长一点:你必须编辑 apache 配置,至少授予它访问 web/ 目录的权限,所以即使你将你的 web 文件夹符号链接到 /var/www,它也不会工作。

Short answer: no.

Bit longer: you will have to edit the apache config at least to give it permission to access the web/ directory, so even if you symlink your web folder to /var/www, it will not work.

别忘他 2024-09-09 04:59:48

这与我的问题非常相似 虚拟主机上的 Symfony(文档根问题)。

这是我在项目根目录中的 .htaccess :

RewriteEngine On
RewriteBase /       

RewriteCond %{REQUEST_URI} ^/images/  [OR]
RewriteCond %{REQUEST_URI} ^/js/      [OR]
RewriteCond %{REQUEST_URI} ^/css/
RewriteRule ^(.*)$ /web/$1 [L]

RewriteCond %{REQUEST_URI} !^/web/
RewriteRule ^(.*)$ /web/index.php [QSA,L]

这解决了我的问题,但 symfony 尝试从文档根生成每个 url(例如使用 url_for ),而不是 url就像 domain.com/my-article 它生成 domain.com/web/my-article
我必须稍微修改我的 PatternRouting 类,以删除每个 url 中的 /web 前缀。我认为这不是最好的解决方案,但它确实有效。

另外,如果我想访问后端应用程序,我必须始终调用 /web/backend.php/ 因为我不想在 .htaccess 中有这么多重写规则。

如果您想查看我的扩展 PatternRouting 类源代码,我会将其粘贴到此处。

This is quiet similar to my question Symfony on virtual host (document root problem).

This is my .htaccess in the project root directory:

RewriteEngine On
RewriteBase /       

RewriteCond %{REQUEST_URI} ^/images/  [OR]
RewriteCond %{REQUEST_URI} ^/js/      [OR]
RewriteCond %{REQUEST_URI} ^/css/
RewriteRule ^(.*)$ /web/$1 [L]

RewriteCond %{REQUEST_URI} !^/web/
RewriteRule ^(.*)$ /web/index.php [QSA,L]

This solved my problem but symfony tries to generate every url (eg. using url_for) from the document root so instead of url like domain.com/my-article it generates domain.com/web/my-article.
I had to slightly modify my PatternRouting class to trim the /web prefix from each url. I think this is not the best solution but it works.

Also if I want to access backend application I have to call always /web/backend.php/ because I don't want to have so many rewrite rules in the .htaccess.

If you want to see my extended PatternRouting class source code I'll paste it here.

紫轩蝶泪 2024-09-09 04:59:48

是的,这是可能的。将所有内容从 web/ 向上复制到文档根目录。编辑index.php以反映这样一个事实:它包含的所有内容现在比以前更接近其当前目录一级(少一级../)。您无需编辑任何其他 Symfony 文件。

Yes, it is possible. Copy everything from web/ up a level to your document root. Edit index.php to reflect the fact that everything it includes is now one level closer to its current directory than it used to be (one less ../). You won't have to edit a single other Symfony file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文