Hello,

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:
http://www.mysite.com/newsite/
http://www.mysite.com/newsite/products/
http://www.mysite.com/newsite/products/sample1/
http://www.mysite.com/newsite/products/sample2/
http://www.mysite.com/newsite/products/sample2/
http://www.mysite.com/newsite/about-us/
http://www.mysite.com/newsite/contact/

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.

So:
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?

Thanks

Remove lines 2 and 3.

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.