Help with htaccess 301 redirects
So, how can I set up my htaccess to redirect all traffic into the sub directory (to fix the incoming links) EXCEPT the index.html in the root directory because it has the landing page.
I don't know how htaccess works well but this is what I have right now.
Order deny,allow
ErrorDocument 404 /404.php
DirectoryIndex index.php index.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$ [OR]
RewriteRule ^.*$ http://example.com/portal/$0 [R=301,L]
So to recap:
Right now EVERYTHING redirects from the root to the subdirectory. I want everything to redirect EXCEPT for index.html in the root directory because it's a landing page.
Thanks!!
5 Replies
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$ [OR]
# this should only grab the root dir's index.html and ignore index.html in subdirectories
RewriteCond %{SCRIPT_URI} !^example.com/index.html$
RewriteRule ^(.*)$ http://example.com/portal/$1 [R=301,L]
MSJ
this so far is best I have:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.(php|html) [NC]
RewriteRule ^.*$ http://example.com/portal/$0 [R=301,L]
but it only works if i specifically write example.com/index.html
It's the only file in there and the irectoryIndex index.html is set but if i just go to the root with nothing else in the url, it forwards me to /portal/
So, I'm close? hahaha. any thoughts?
try following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{REQUEST_URI} !^/index\.(php|html)$ [NC]
RewriteRule ^(.*)$ http://example.com/portal/$1 [R=301,L]
besides, you said you are using wordpress, so I assume you removed previous rewrite entries for wordpress in your root directory.
@Tamerax:
thanks for that but unfortunatly it just forwards everything right to portal still.
this so far is best I have:
RewriteEngine On RewriteCond %{REQUEST_URI} !^/index\.(php|html) [NC] RewriteRule ^.*$ http://example.com/portal/$0 [R=301,L]
but it only works if i specifically write example.com/index.html
It's the only file in there and the irectoryIndex index.html is set but if i just go to the root with nothing else in the url, it forwards me to /portal/
So, I'm close? hahaha. any thoughts?
And yes, the directory is empty except for the htaccess file, the index.html and the subdirectory folder.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.(php|html) [NC]
RewriteCond %{REQUEST_URI} !^/$ {NC]
RewriteRule ^.*$ http://example.com/portal/$0 [R=301,L]
Still not working. everything is forwarding to /portal/ unless it has it specifically written index.html