2

I have a website abc.com were i have kept all my files and folders. Now I have created a folder called "newsite" and moved all the files over to there. Now i want if my user type abc.com in browser it will automatically redirect them to abc.com/newsite

I am using a linux server with godaddy hosting. I know this can be done through htaccess file. Can anyone help me on this?

I am using this in htaccess file but this does not work

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.abc.com$
RewriteRule (.*)$ /newsite$1 [R,L]
</IfModule>

Thank you so much in advance

Prix
  • 18,774
  • 14
  • 65
  • 127
Deepak Ranjan Jena
  • 437
  • 5
  • 11
  • 23
  • possible duplicate of [.htaccess rewrite to redirect root URL to subdirectory](http://stackoverflow.com/questions/990392/htaccess-rewrite-to-redirect-root-url-to-subdirectory) – C Travel Sep 25 '13 at 09:46

3 Answers3

7

This should do it:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/newsite [NC]
RewriteRule ^ /newsite%{REQUEST_URI} [R=301,L]

The RewriteCond checks if the URL starts with /newsite if not it will redirect the user to it.

Prix
  • 18,774
  • 14
  • 65
  • 127
0

Try this solution:

RewriteRule ^xxx/?([^/].*)?$ old/xxx/$1 [L]

Or

 RewriteRule ^(.*)directory(.*)$ $1otherdir$2 [QSA,L,R=301,NC]
RDK
  • 4,475
  • 2
  • 18
  • 27
0

Hey friend, is correct:

RewriteEngine On RewriteBase /

RewriteCond %{REQUEST_URI} !^/yournewfolder [NC] RewriteRule ^ /yournewfolder%{REQUEST_URI} [R=301,L]

Only this in your .htacces that is within your public_html folder (root of site)

The new folder is the folder that contains the files of your website. If you use wordpress, use Softaculous to clone the entire content of your site to the new folder.

Remember that you will have to change the information for your database. - Log into your phpMyAdmin account, export your database to a location on your computer (use the option Custom - display all possible options to export and maintain a backup of your database exported - if you miss something, you will have this insurance file to import it again).

Then open your yourdatabasename.sql file on your php editor, use the replace option and make the following change.:

EX: yoursite.com
(Replacing option to) yoursite.com/yournewfolder

save the edited file. Now go back to your phpMyAdmin account and delete your old database (Selecting all tables and using the delete option), after deleting, go to the Import option and import your new database already edited.

Have a great day.

A.Torres
  • 1
  • 3