Question

I have a account in a shared hosting(www.1and1.com) and i want a .htaccess redirecting all the request to a different folder. (I'm trying to setup a symfony2 app)

for example, on request to:

http://www.mydomain.com/

internally respond:

http://www.mydomain.com/folder_x/folder_y

i already try this(do not work):

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/(.*)$ /folder_x/folder_y/$1 [R,L]

Thanks

Was it helpful?

Solution

Leading slash isn't matched in RewriteRule in .htaccess. Change your rule to:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/folder_x/folder_y/ [NC]
RewriteRule ^ /folder_x/folder_y%{REQUEST_URI} [L]

Some other improvements I have made:

  • Removed R flag since you wanted internal rewrite only
  • Added RewriteCond before rule to avoid rewriting URIs that already start with /folder_x/folder_y/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top