I have a website in Wordpress. Example: http://www.mysite.com
Than I developed a new theme for the website and I have created a new directory on server for developement and testing only. The URL is http://www.mysite.com/newsite/

Now Google scanned my this testing website and added URL from it. So google has added:

There are more than 100 pages so I cannot add 301 redirection for each URLs.

So I think to add a conditional HTACCESS rule for this.

http://www.mysite.com/newsite/ will redirect to http://www.mysite.com/
http://www.mysite.com/newsite/products/ will redirect to http://www.mysite.com/products/
http://www.mysite.com/newsite/products/sample1/ will redirect to http://www.mysite.com/products/sample1/
and so on.

I have added this HTACCESS rule but this is not working:

RewriteEngine on
RewriteBase /newsite/
RewriteCond %{HTTP_HOST} ^newsite/\.
RewriteRule ^newsite/(.*)$ /$1 [L,R=301,QSA].

Please note that the root path (www.mysite.com) also contains Wordpress HTACCESS so if this may give problem?

Can anyone help me to create rule for this?


Recommended Answers

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

Jump to Post

All 4 Replies

Thanks for reply.
It's not working. I removed 2nd and 3rd line but still it's not working.

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

Thanks coreyavis
Your solution is working perfectly :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.