d3javu999
d3javu999

Reputation: 323

How to redirect to a subfolder with htaccess

How I can redirect to a specific subfolder with htaccess? I have a structure like this

dfg/pubblication1/index.html

In the folder directory there is no index.html file but only the .htaccess file

What I want to do is that when a user is linked to http://domain.ext/folder will be automatically redirect to http://domain.ext/folder/subfolder/index.html

I have something like this

<IfModule mod_rewrite.c>
    RewriteEngine On   
    RewriteCond %{REQUEST_URI}  !^/dfg     [NC]
    RewriteRule ^(.+)  /dfg/pubblication1/$1  [NC]
</IfModule>

But unfortunately doesn't work. Thanks in advance

Upvotes: 1

Views: 1096

Answers (1)

Pier-Luc Gendreau
Pier-Luc Gendreau

Reputation: 13814

This is what I use:

RewriteCond %{REQUEST_URI} !^/static/
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -d
RewriteRule ^(.*)$ /static/$1 [L]

Line 1: Check if the request already contains the subfolder you want to redirect (to avoid an infinite loop).

Line 2 & 3: Verify if the request is a file or directory

Line 4: Do the actual rewriting

Upvotes: 1

Related Questions