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条)

报告相同问题?

悬赏问题

  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新
  • ¥50 深度强化学习解决能源调度问题
  • ¥15 一道计算机组成原理问题