Permanent redirect to subfolder with .htaccess

I am creating a Symfony2 project on a shared host and I am having some problems. Symfony2 by default has its dispatchers or core files (which on many systems is a file index.php

) inside a directory /web

, so if I move the entire project public_html

to shared hosting it won't work until I add it /web

to the end of the URL. This is bad and noise for users as they know the page for this domain. I am trying to do a redirect using the .htaccess

following:

//301 Redirect Entire Directory
RedirectMatch 301 /(.*) /web/$1

//Prevent directory listings
Options All -Indexes

      

But it hasn't been working since the hosting said that these lines are bad in the .htaccess file, then how can I deal with this issue?

+3


source to share


2 answers


In the root .htaccess you can use this rule mod_rewrite

:



//Prevent directory listings
Options All -Indexes

RewriteEngine On

RewriteRule ^((?!web/).*)$ /web/$1 [L,NC,R=301,NE]

      

+1


source


Do you know when you buy some kind of hosting and you do your first FTP access in your favorite client?

You can see something like this:

/
    ftp/
    httpdocs/
    access_log.txt

      

The directory web/

is httpdocs/

in this scenario. Sometimes the directory is called public_html

, www

or simply html

.



At the end of the day, they are all the same.

Your symfony project catalogs app/

, src/

, vendor/

should be at the root of the public.

Usually on monitored servers, you can create virtual hosts where you specify the document root. However, if you are trying to load the site, move everything to the parent directory and rename the web directory to whatever server you configured to use.

0


source







All Articles