2013-05-13 62 views
0

我想用mod_rewrite。我在这/var/www/.htaccess代码Symfony mod_rewrite只有主路由工作

<IfModule mod_rewrite.c> 

    Options +FollowSymlinks 
    RewriteEngine On 
    #AllowOverride All 

    #Allow from All 
    #RewriteBase /WorldClock 
    #RewriteBase WorldClock/web/app.php 
    # Explicitly disable rewriting for front controllers 
    RewriteRule ^/web/app_dev.php - [L] 
    RewriteRule ^/web/app.php - [L] 

    # Fix the bundles folder 
    #RewriteRule ^(.*)$ WorldClock/web/app.php/test [QSA,L] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    # Change below before deploying to production 
    RewriteRule ^(.*)$ WorldClock/web/app.php [QSA,L] 
    #RewriteRule ^(.*)$ WorldClock/web/app_dev.php [QSA,L] 

</IfModule> 

如果行是注释,意味着它做出内部服务器错误 我的项目是在/var/www/WorldClock/..文件夹CSS | JS | IMG我转移到/var/www 如果我试图进入localhost那么它工作正常。但是,如果我在链接点击此网址这样http://localhost/info/12然后我得到

Not Found The requested URL /info.xml/12 was not found on this server. 

一切正常,没有的.htaccess。 mod_rewrite在phpinfo()中打开;我使用symfony2和Ubuntu

回答

0

为了我们能够提供帮助,至少我们需要您的web服务器的配置。我认为这只是web服务器配置不正确的问题。如果我的答案是关闭的,请用有意义的错误消息更新您的问题,即检查您的error.log和更详细的说明哪些路由可以工作,哪些不可以,因为我不完全确定您是否可以访问本地主机并查看默认的“It work's”页面或项目的首页,以及是否可以访问您的资产?

/etc/apache2/sites-available/只需创建一个新的文件worldclock.conf

<VirtualHost *:80> 
    ServerName localhost 

    DocumentRoot /var/www/WorldClock/web 
    <Directory /var/www/WorldClock/web> 
     # enable the .htaccess rewrites 
     AllowOverride All 
     Order allow,deny 
     Allow from All 
    </Directory> 
</VirtualHost> 

现在你只需要启用新的虚拟主机,然后重新启动您的web服务器:

sudo a2ensite worldclock 

# When both hosts use localhost as ServerName there might be some problems 
# so we'll disable the default host, which we won't need anyway(?) 
sudo adissite default 

sudo service apache2 restart 

如果这只是你的开发环境您可以使用PHP的内部Web服务器(假设您已安装5.4),这将缓解一些所需的工作,因为您只需运行:php app/console server:run以使其运行。然后,您可以通过以下方式访问您的应用:默认为http://localhost:8000

要确定安装了哪个PHP版本,请在您的终端中运行:php -v