Jump to content

please give code to redirect site's root to sub folder


Ricky.

Recommended Posts

I have my site at www.domain.com/subfolder/

 

hence I want www.domain.com to 301 redirect to /subfolder

Also, domain.com to /subfolder

 

Earlier I was using this simple

redirect 301 /index.php http://www.domain.com/subfolder/  

But it was causing problem as www. and without www it was looking different as well as no subdomain was working as it was also getting redirected to www.domain.com/subfolder

 

Then I used this :

RewriteCond %{HTTP_HOST} !^subdomain1\.domain\.com
RewriteCond %{HTTP_HOST} !^subdomain2\.domain\.com
Rewriterule ^(.*)$ http://www.domain.com/subfolder/$1 [r=301,nc]

 

Now, with above, subdomain1.domain.com, subdomain2.domain.com are working fine but it is also redirecting any other folder than /subfolder to www.domain.com/subfolder ..

ie. if someone tries to access www.domain.com/anothersubfolder then it is getting redirect to www.domain.com/subfolder

 

Any help is greatly appreciated ..

 

PS: This 301 redirect stuff has really messed my sites ranking as for main keywords its gone to 5th 6th pags from no.1 position ..

Link to comment
Share on other sites

for one of my sites, I have www.domain.com redirect to www.domain.com/main.php so I have a file index.php and all it has on it is:

 

<?php

header("Location: main.php");

?>

 

There are other ways to do what you need, but to me, this is the easiest. and you can easily modify where it redirects by editing this file.

 

Note: if you have an index.htm page, you probably won't be able to know if going to domain.com will access index.htm or index.php so basically, I suggest checking your root directory for any other file named index

Link to comment
Share on other sites

Hi Danny, that is good that you suggested it but my need are different, I need to 301 redirect forum root to subfolder , its not just a file. Also, I want to take care about conical name.. ie. I want all none www name to redirect to www version too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.