.htaccess 相当于baseurl?

发布于 2024-08-26 23:31:15 字数 1235 浏览 5 评论 0原文

我正在尝试在共享服务器上安装 Symfony 并尝试复制 httpd.conf 命令:

# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080

# This is the configuration for your project
Listen 127.0.0.1:8080

<VirtualHost 127.0.0.1:8080>
  DocumentRoot "/home/sfproject/web"
  DirectoryIndex index.php
  <Directory "/home/sfproject/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
  <Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

我需要使用 .htaccess 来执行

此操作 重定向部分是使用以下命令在根目录中完成的:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^symfony.mysite.ca [nc]
rewriterule ^(.*)$ http://symfony.mysite.ca/web/$1 [r=301,nc] 

对于别名,我已经尝试过使用:

RewriteBase /

但没有成功。

主要问题是位于 /web 文件夹中的 index.php 文件在其图像和脚本路径中使用 /web 路径。所以而不是

href="/css/main.css"  //this would work

使用

href="/web/css/main.css"  //this doesn't work, already in the /web/ directory!

任何想法?谢谢!

I'm trying to install Symfony on a shared server and am attempting to duplicate the httpd.conf command:

# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080

# This is the configuration for your project
Listen 127.0.0.1:8080

<VirtualHost 127.0.0.1:8080>
  DocumentRoot "/home/sfproject/web"
  DirectoryIndex index.php
  <Directory "/home/sfproject/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
  <Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

I need to do so using .htaccess

The redirect portion was done in the root using the following:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^symfony.mysite.ca [nc]
rewriterule ^(.*)$ http://symfony.mysite.ca/web/$1 [r=301,nc] 

For the alias, I've tried using:

RewriteBase /

but no success.

The main issue is that the index.php file residing in the /web folder uses the /web path in its path to images and scripts. So instead of

href="/css/main.css"  //this would work

it uses

href="/web/css/main.css"  //this doesn't work, already in the /web/ directory!

Any ideas? Thanks!

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

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

发布评论

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

评论(1

梦初启 2024-09-02 23:31:15

您可以使用...

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

来防止重写引用实际文件的 url,从而防止通用重写将第二个 /web 添加到 URL 中。

You can use...

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

to prevent urls that refer to actual files from being rewritten, thus preventing the generic rewrite from adding a second /web into the URL.

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