Mobile app version of vmapp.org
Login or Join
Alves908

: RewriteRule ^/folder(.*)$ /folder/subfolder/ [R=301,NC,L] As just mentioned in this other answer... in per-directory .htaccess files the RewriteRule pattern matches the URL-path less the directory-prefix,

@Alves908

RewriteRule ^/folder(.*)$ /folder/subfolder/ [R=301,NC,L]



As just mentioned in this other answer... in per-directory .htaccess files the RewriteRule pattern matches the URL-path less the directory-prefix, so the URL-path that is matched does not start with a slash. So, the pattern should be more like: ^folder(.*)$

Unless you have a requirement to use the root .htaccess file, I would create a .htaccess file in the directory you are redirecting from instead. So, in the /folder/.htaccess file (not the document root), try the following:

RewriteEngine On
RewriteBase /folder

RewriteCond %{REQUEST_URI} !^/folder/subfolder
RewriteCond %{REQUEST_URI} !^/folder/exclude-file1.html$
RewriteCond %{REQUEST_URI} !^/folder/exclude-file2.html$
RewriteCond %{REQUEST_URI} !^/folder/exclude-dir
RewriteRule (.*) subfolder/ [R=302,L]


The NC flag is not required here.

The first RewriteCond directive is to prevent a redirect loop, since we are redirecting to a subfolder of the folder we are redirecting from!

I've also used a 302 (temporary) redirect. When you are sure it's working OK, change to a 301 (permanent) - if that is the intention. 301s are cached by the browser so can make testing problematic.

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Alves908

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme