简体   繁体   中英

how to redirect routing with .htacces

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 ?

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...

Maybe the PHP header function?

<?php header("Location: http://www.example.com/"); exit; ?>

PHP: header

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM