Ceeege
Ceeege

Reputation: 1

.htaccess or cPanel redirects. Redirect pagename in folder to subdomain/pagename (all folder contents)

I am trying to get a redirect set up for my site. I have three subdomains which I use

1) (www.)mysite.com

2) sub.mysite.com

3) anothersub.mysite.com

I initially didn't use subdomains and had all my pages in a www.mysite.com/*.php format.

I am trying to add a redirect to make all the pages under the /myfolder/ folder redirect to sub.mysite.Com/ (NB sub is the same name on my site as the myfolder folder)

I have tried setting up a redirect through cPanel but all the combinations have resulted in 404 errors when I try them. I have also tried various things in .htaccess which resulted in many 404 errors.

I added a simple redirect in cPanel and get the following

e.g.

www.mysite.com/myfolder/myfolder_mypagename.php

should redirect to

sub.mysite.Com/myfolder_mypagename.php

but instead it redirects to

sub.mysite.com/_mypagename.php (missing out the "myfolder" part of the pagename)

Can you assist me in this please? It's driving me bonkers and my hosting company said it wasn't possible (which I find hard to believe!)

Upvotes: 0

Views: 1280

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

This answer is assuming your are facing the issue that, when creating a subdomain through cpanel and pointing it to the desired directory, some part of the urls get striped.

Create you subdomain through cpanel, and make it point to the root directory (just like www.mysite.com), then use this in your htaccess :

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$
RewriteRule ^myfolder/(.*)$ http://sub.mysite.com/$1 [L,QSA,R=301]

RewriteCond %{HTTP_HOST} ^sub\.mysite\.com$
RewriteRule ^(.*)$ myfolder/$1 [L,QSA]

Upvotes: 0

Related Questions