dtz46697 2013-11-21 12:49
浏览 74
已采纳

如何使用.htaccess重定向路由

My problem is i bought a shity hosting and now i can not set my own config. I need to do it by .htaccess file. Here is what i manage to do:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/Project/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Project/web/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ Project/web/app.php [L]

I know that this will not work with some website software like mine. and I also need to modify the $base_url, $live_site or other configuration settings in those to finish the process.

To make it all clear with this settings when i enter my domain i start from subdirectory i choose. but when i try to go to another page its return 404 error.

I have an idea how to make it work, its need to redirect also routing so for example www.domain.com/page need to be redirected to www.domain.com/Project/web/page if anyone know how to do it ?

  • 写回答

2条回答 默认 最新

  • dtvpe4837413 2013-11-21 13:02
    关注

    I installed symfony on a shared hosting service one time.

    That's what I had to do to make Symfony work :

    in the public directory there is the structure of the project :

    /app
    /src
    /vendor
    /web/.htaccess
    /.htaccess
    

    In /.htaccess I wrote :

    SetEnv PHP_VER 5_3
    SetEnv REGISTER_GLOBALS 0
    
    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /web
    
       RewriteCond %{REQUEST_URI} \.(css|gif|ico|jpg|js|png|swf|txt|pdf|doc|docx|mp3|svg)$
       RewriteRule ^(.*)$ $1 [QSA,L]
    
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ web/app.php/$1 [QSA,L]
     </IfModule>
    

    in /web/.htaccess I wrote :

    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app.php [QSA,L]
    </IfModule>
    

    That's all...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站