Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permanent redirect to subfolder with .htaccess

I'm setting up a Symfony2 project on a Shared Host and I'm having some issues getting things done. Symfony2 by default has their dispatch controllers or main files (what in many system is the file index.php) inside /web directory so if I move all the project to public_html on the shared hosting then it won't works until I append the /web to the end on the URL. This is bad and noise for users since they know the page for it's domain. I'm trying to make the redirect using .htaccess as follow:

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

//Prevent directory listings
Options All -Indexes

But it's not working since the hosting said that this lines are bad in the .htaccess file, then how I can get ride of this problem?

like image 739
ReynierPM Avatar asked Dec 31 '25 09:12

ReynierPM


1 Answers

In root .htaccess you can use this mod_rewrite rule:

//Prevent directory listings
Options All -Indexes

RewriteEngine On

RewriteRule ^((?!web/).*)$ /web/$1 [L,NC,R=301,NE]
like image 145
anubhava Avatar answered Jan 03 '26 14:01

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!