Forum Moderators: phranque
Hope that i can get some help here. I just created a new site www.abc.com/newsite and would like to redirect all links from old website to the new one. i.e www.abc.com to www.abc.com/newsite. By referring to another thread i got it working [sort of like ctrl c ctrl v thing] but only the admin directory in www.abc.com/newsite/admin also being redirected to www.abc.com/newsite/
To simplify the scenario:
(1) Redirect all from www.abc.com --> www.abc.com/newsite/
(2) Except robots.txt located in public_html
(3) Except www.abc.com/newsite/admin directory should not be redirected.
The structure of my website is as follow:
public_html <-- www.abc.com
-- robots.txt
-- .htaccess
-- images
-- all files and pages for old site
-- NEW FOLDER for NEW SITE <-- www.abc.com/newsite
------ images
------ all files and pages for new site
Please refer to my .htaccess file as follow:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST}!^abc\.com
RewriteCond %{REQUEST_URI}!^/robots\.txt
RewriteRule (.*) [abc.com...] [R=301,L]
Thanks in advance to everyone up here.
To answer your question as stated and as I understand it, you'd need to do this:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond $1 !^newsite/
RewriteCond $1 !^robots\.txt$
RewriteCond $1 !^admin/
RewriteRule (.*) http://www.example.com/newsite/index.php [R=301,L]
But a fundamental question is, why are you redirecting these requests, instead of rewriting them? By redirecting them, you give the visitor a complicated URL, expose the internal workings of your server, and require all the search engines to throw away your old URLs and start over. An internal rewrite simply substitutes the new content for the old content using the same old URL.
In example.com/.htaccess:
# Externally redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Internally rewrite all requests except /robots.txt and /admin to /newsite subdirectory
RewriteCond $1 !^newsite/
RewriteCond $1 !^robots\.txt$
RewriteCond $1 !^admin/
RewriteRule (.*) /newsite/$1 [L]
# Internally rewrite all /newsite requests except images, css, & js to /newsite/index.php
RewriteCond $1 !\.(gif¦jpe?g¦png¦css¦js)$
RewriteCond $1 !^index\.php$
RewriteRule ^(.*)$ /newsite/index.php [L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim