1

i am trying to auto 301 redirect from domain.com to domain.com/v2 ive tried this code

RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^$ /v2/ [NC,L]

also tried

Redirect 301 / /v2/

i get the error 'site has tried to redirect you too many times'

is there any way to do this?

thanks for any help

Tintinabulator Zea
  • 2,119
  • 3
  • 15
  • 24

2 Answers2

2

Untested but this should redirect both domain.com and www.domain.com to the v2 subfolder:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ v2 [L]

You need to replace example.com with your actual domain because of posting restrictions.

I suppose you have an endless redirect because you are not matching the end of the domain string with $. Redirection should only take place at the root domain.

Anonymous
  • 1,403
  • 1
  • 6
  • 5
1

you can use a write rule with ^$ representing the root of the site and rewrite it to the selected folder

RedirectMatch ^/$ /v2/

it redirects the root and only the root URL.

or also you can use

RewriteEngine On
RewriteRule ^$ /v2[L]

If you want external redirection(301) you can use R flag

RewriteRule ^$ /v2[L,R=301]

Another way to use it with RewriteEngine

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ v2 [L]

Original Answers

I hope I've helped