Naty Bizz
Naty Bizz

Reputation: 2342

Redirect to another folder with htaccess and hide the folder's name

I had a paid domain, I did put a folder with the name of the domain (mysite.net) in the server

I don't want to pay for the domain anymore, so I want to use the default subdomain given by my hosting service (mysitenet.ipage.com) but the problem is what I said above, it exists a folder with the name of my paid domain, like this:

/
  /mysite.net
  /cgi.bin

I read this solution to try redirection:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

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

with this rules I go to mysitenet.ipage.com and redirects me to mysitenet.ipage.com/mysite.net as I want, but is there a way to hide the 'mysite.net' part?

Upvotes: 3

Views: 295

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You can put this code in your htaccess (which has to be in root folder)

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^(?!mysite\.net/)(.*)$ mysite.net/$1 [L,QSA]

EDIT: if you want to avoid duplicate content and also redirect /mysite.net/something to /something

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/mysite\.net/([^\?\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteRule ^(.*)$ mysite.net/$1 [L,QSA]

Upvotes: 1

Related Questions