如何DirectoryIndex控制器路由?

时间:2013-04-22 05:26:52

标签: .htaccess symfony apache2 directoryindex

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

注意:' 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>

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

编辑:根据给出的答案更新.htaccess。但仍然没有工作

2 个答案:

答案 0 :(得分:0)

在顶部插入RewriteRule

RewriteRule ^$ home [L]

这将重定向到/home,如果您希望客户端看到此网址,则必须在规则中添加R标记。

答案 1 :(得分:0)

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

Redirect / /home

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