The Little Guy Posted June 28, 2011 Share Posted June 28, 2011 I have directories that don't have index pages, instead of using: Options -Indexes I just want to redirect to my main site. how can I do that? Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/ Share on other sites More sharing options...
requinix Posted June 28, 2011 Share Posted June 28, 2011 RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ / [L,R] (The Cond checks if the request was for a directory.) Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236099 Share on other sites More sharing options...
The Little Guy Posted June 29, 2011 Author Share Posted June 29, 2011 hmmm.... doesn't seem to work. This is on a sub-domain, and I want to redirect to my "main" domain. The sub-domain has all the images user upload, none of the directories have index files, so if they don't hit a file directly, such as a jpg it needs to redirect them to the main site. I don't know if that helps at all, but the code you gave doesn't redirect me at all (even after changing / to http://mysite.com) Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236155 Share on other sites More sharing options...
cags Posted June 29, 2011 Share Posted June 29, 2011 The second half of the RewriteRule is the path you will be redirected to. In the case of requinix's code / represents document root. If the .htaccess file is on a sub-domain this will refer to the document root of the sub-domain. If you wish to go to the home page of main domain, just swap the forward slash out with your domain name. RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ http://www.mysite.com/[L,R] Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236176 Share on other sites More sharing options...
The Little Guy Posted June 29, 2011 Author Share Posted June 29, 2011 @cags (previous post): the code you gave doesn't redirect me at all (even after changing / to http://mysite.com) Location: http://img.hostbox.us RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ http://hostbox.us/ [L,R] Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236559 Share on other sites More sharing options...
cags Posted June 29, 2011 Share Posted June 29, 2011 It was purely a hypothesis, I'm not entirely surprised it didn't work, though I couldn't tell you the reason, I was just making a suggestion on the solution you'd already tried. You could just check if the requested path ends with a forward slash. RewriteRule /$ http://hostbox.us/ [L,R] Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236567 Share on other sites More sharing options...
requinix Posted June 29, 2011 Share Posted June 29, 2011 You could just check if the requested path ends with a forward slash. Note: this works because Apache will redirect any "dir" request to "dir/" by default. That behavior can be turned off with a DirectorySlash, in which case checking for a trailing slash only works when the users visit "dir/" directly. Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236579 Share on other sites More sharing options...
The Little Guy Posted June 30, 2011 Author Share Posted June 30, 2011 This works: Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !-d$ RewriteRule .* http://hostbox.us [R=307,L] Quote Link to comment https://forums.phpfreaks.com/topic/240654-no-indexes-redirect/#findComment-1236792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.