Jump to content

301 Redirect Entire Directory And Sub Dirs


Recommended Posts



I setup a 301 redirect for a directory that contained numerous subdirectories, (all got indexed by Google accidentally.)


Here is an example of the code:


>redirect 301 /olddir http://www.****/index.php


However if I go to a link like this:



It ends up going here:



I don't know the names of all the subdirectories, there are hundreds too. So I was wondering if there is a way to include all subdirectories in 1 line of code.


Thanks for any suggestions. :P


oye, sorry about the URLs, i forgot those are probably not allowed... trying to turn them off... ok got it.

Edited by mdedens
Link to comment
Share on other sites

Possibly... I have this line above it:

(my old site had an index.shtml page, but the new one is .php)


>redirect 301 /index.shtml http://www.****.com/index.php


and this below it, for image protection and redirecting the non-www domain:


>Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_Host} ^****.com [NC] 
RewriteRule ^(.*)$ http://www.****.com/$1 [L,R=301]
RewriteCond %{HTTP_REFERER} !^http://****.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://****.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www.****.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.****.com [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]


Sorry I shoulda posted this in the first place. :P


(not sure if that bottom part is the most efficient way to redirect and image protect, i keep seeing many different ways and don't know what's best)

Edited by mdedens
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...