Search code examples
.htaccesssymfonysubdirectorybase-url

How to modify the $base_url, $live_site with .htaccess file?


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. And my question is hot to do it to make it work ? How to edit this configuration settings ?

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.


Solution

  • I did it by setting .htaccess file in public directoly like this:

    SetEnv PHP_VER 5_4
    SetEnv REGISTER_GLOBALS 0
    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /Project/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 ^(.*)$ Project/web/app.php/$1 [QSA,L]
    </IfModule>
    

    and in the wanted subdirectory to be all redirected i set .htaccess file like this:

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

    By doing it i dont have to be worried about changin all routing and modify the $base_url or $live_site.