【问题标题】:How to DirectoryIndex a controler route?如何目录索引控制器路由?
【发布时间】:2013-04-14 22:26:27
【问题描述】:

使用我当前的配置,每次我输入 something.com 时,它都会显示 app_dev.php,因为我当前的重写规则是正确的。但我想要的是,如果用户键入 www.something.com,它将自动定向到 www.something.com/home

注意:“家”是我的一个捆绑包下的一条路线

这是我目前的配置

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin admin@something.com
  ServerName  www.something.com

  # Index file and Document Root (where the public files are located)
#  DirectoryIndex home    # I have already tried this, nothing happens
  DocumentRoot /home/user/public/something.com/web/symfony/web

  # Log file locations
  LogLevel warn
  ErrorLog  /home/user/public/something.com/log/error.log
  CustomLog /home/user/public/something.com/log/access.log combined
</VirtualHost>

.htaccess 在 Symfony/web 中

<IfModule mod_rewrite.c>
    RewriteRule ^$ app.php/home [L]

    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
   RewriteRule ^app_dev.php - [L]
   RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    RewriteRule ^(.*)$ app.php [QSA,L]
    #RewriteRule ^(.*)$ app_dev.php [QSA,L]

</IfModule>

实际的 url 必须是 www.something.com/app.php/home(当前规则隐藏了 app.php)

编辑:根据给出的答案更新了 .htaccess。但还是不行

【问题讨论】:

    标签: .htaccess symfony apache2 directoryindex


    【解决方案1】:

    在您的 .htaccess 或 VirtualHost 中,使用 mod_alias 获取临时重定向 (302)。您不必担心它与您的应用程序 URL 重写冲突。

    Redirect / /home
    

    http://httpd.apache.org/docs/current/mod/mod_alias.html

    【讨论】:

      【解决方案2】:

      在顶部插入RewriteRule

      RewriteRule ^$ home [L]
      

      这将重定向到/home,如果你想让客户端看到这个URL,你必须在规则中添加一个R标志。

      【讨论】:

      • 它返回 /home 在此服务器中找不到。实际上,我的原始网址看起来是 www.something.com/app.php 。我当前的配置隐藏了 app.php,我需要在每个页面中都有它。简而言之,当我尝试你的建议时,我应该有 www.something.com/app.php/home。它删除了 app.php
      • 仍然无法正常工作。 404 未找到。这是实际的链接 --> cloud-pod.net 返回 404 但 cloud-pod.net/home 返回页面。
      • 还是一样。当我查看我的 apache 错误日志时。实际上没有任何报告。
      • @Saber 所有这些规则,前一个和这个,都在我的测试环境中工作,所以我不知道这里有什么问题。无论如何,我没有想法,对不起。
      • 谢谢。我很想知道是什么可能导致它不起作用。
      猜你喜欢
      • 1970-01-01
      • 2011-05-09
      • 2017-12-30
      • 1970-01-01
      • 2019-10-22
      • 2022-01-17
      • 2020-11-18
      • 1970-01-01
      • 2019-12-12
      相关资源
      最近更新 更多