I've moved the website inside a root's subdirectory, but wish to keep your url's working. I've already accomplished this using following rule in htaccess:

 RewriteCond % !^/subdir  [NC]

 RewriteRule ^(.*)$ /subdir/$1 [L,NS]

Now issue is that the given page (allows say index.php) could be utilized by two url's:



I'm not going this to occur to prevent confusion for customers also to avoid same content being indexed two times by search engines like google. I'm not too good with htaccess, but things i did ended up being to do exterior redirect to my very own site by creating another rule in htaccess:

RewriteRule ^subdir/(.*)$ http://mysite.com/$1 [L,R,NS,NC]

But problem is this fact produces a never-ending loop through sub-demands. Normal request results in sub-request fetching page from "subdir" subdirectory, but that sub-request causes the 2nd rule to complete exterior redirect to my website, beginning the loop once again. NS flag, I discovered later, is useless just in case of exterior redirects. What exactly I needed to request is, how do you break this loop? OR how do you transfer the request made using "mysite.com/subdir/index.php" hyperlink to "mysite.com/index.php"?

The very first rule you published is appropriate

RewriteCond % !^/subdir  [NC]

RewriteRule ^(.*)$ /subdir/$1 [L,NS]

The 2nd rule you will need to change. You should't perform a Rewrite but a Redirect (ideally a 301).

This really is useful in acquiring the preferred results as well as in not receiving your articles indexed two times by search engines like google.

Since a redirect really transmits an http-response that states in which the resource has moved it doesn't create an interior loop.