Redirecting to a subdirectory from root

I am new here on InfinityFree and trying to set up my site www.villaduparc.info
To start with I have loaded up the old website in a directory …/villaduparc.info/htdocs/VDP-Old/ Later I plan to move over the new wordpress site I have developed. I don’t want to fill up the root directory - that being the reason for moving everything to the subdirectory VDP-Old.

My problem is getting traffic directed there. When someone writes www.villaduparc.info I want the redirected to www.villaduparc.info/VDP-Old
WHere I had things hosted previously I would set up a redirect www.villaduparc.info to www.villaduparc.info/VDP-Old I tried doing this on cpanel by using the redirects: Add/Remove Redirects I changed the villaduparc.freecluster.eu to villaduparc.info and clicked the button “alter redirects”. On the next page I filled in http://villaduparc.info/VDP-Old and clicked the butoon “Redirect itl”. The result was an error message (403) Forbidden You don’t have permission to access /panel/indexpl.php on this server.

What am I doing wrong ?

Anyway I thought I could do it a different way and copied a htaccess file I had from before and placed it in /villaduparc.info/htdocs/ The file looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?villaduparc.info$
RewriteCond %{REQUEST_URI} !^/VDP-Old/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /VDP-Old/$1
RewriteCond %{HTTP_HOST} ^(www.)?villaduparc.info$
RewriteRule ^(/)?$ VDP-Old/index.html [L]

But that didn’t help either. I just get rerouted to the error page: https://infinityfree.net/errors/404/

ANy suggestions for reouting traffic to www.villaduparc.info to www.villaduparc.info/VDP-old ?

Thanks in advance

First setup an custom erorr 404 page. just paste this line below into your .htaccess file

ErrorDocument 400 /400-page.html

And then save your file and revisit your website now you get info about from where you’re redirected to.

Alternative

Using .htaccess

Place this code into your .htaccess file

DirectoryIndex VDP-Old.html VDP-Old.php VDP-Old.htm

Using PHP
Place this code in the top of your index.html file

header("Location: /VDP-Old");
1 Like

First of all, never use the Redirects tool to redirect back to the same domain or a domain in the same folder. I’m not sure why the tool lets you do this in the first place, because it will always lead to a redirect loop.

Do I understand correctly you ONLY want to redirect http://www.villaduparc.info and http://villaduparc.info to http://www.villaduparc.info/VDP-old ? You don’t want to redirect things like http://www.villaduparc.info/blabla to http://www.villaduparc.info/VPD-old/blabla ?

Because if so, I would personally skip the .htaccess route entirely and just create a file with the name index.php and contents like this:

<?php
header('Location: http://www.villaduparc.info/VDP-Old/');
echo "Redirecting...";

If you also want to capture subdomains, that can be done with .htaccess rules, but it’s a bit more involved.

6 Likes

Thanks for trying to help me.

  1. I made an error page and put it in the villaduparc.info/htdocs folder, and modified my htaccess file in the same folder - but it still comes up with the standard infinity error page

  2. I modified the htaccess file in villaduparc.info/htdocs folder according to your suggestions - but no help

  3. I tried adding the PHP code to the top of my index.htm file so the first 3 lines are:
    header(“Location: /VDP-Old”);

but that did not help.

So to iterate:

  1. I have entered an addon address villduparc.info via cpanel - which created a directory villaduparc.info and under that a directory called htdocs.
  2. I have manually moved the old site in to a directory villaduparc.info/htdocs/VDP-Old
  3. Everything works fine in the root directory (ie villaduparc.info).
  4. Everything works fine if I type www.villaduparc.info/VDP-Old/
  5. I am trying to get any user entering www.villadupar.info or villaduparc.info to go one folder down to villaduparc.info/VDP-Old/

I am just having a really hard time getting my head around this

Thanks for the help. To answer your questions - in the villaduparc.info/htdocs folder there was nothing. Everything was in villaduparc.info/htdocs/VDP-Old . By everything I mean htm files and image folder with image files. I do not have subdomains.

I wrote an index.php file where I copied the text you specified and placed it in the villaduparc.info/htdocs folder

I wrote an index.php file and copied the text you specified and placed it in the villaduparc.info/htdocs folder - but users still do not get rerouted to the subfolder. However I did discover that if I entered www.villaduparc.info/index.php in the browser then things seem to work.

So maybe I am a little closer - but still not there yet.

OK, after a lot of trial and error and googling - this seems to work:

  1. a 404-page.htm for errors in villaduparc.info/htdocs folder
  2. a htaccess file with the content below in the same folder as the error page
# redirect from root to subdirectory
RedirectMatch ^/$ /VDP-Old/

# redirect on 404 to subdirectory
ErrorDocument 404 /404-Page.htm

This is where I found the solution: 
https://serverfault.com/questions/9992/how-to-get-apache2-to-redirect-to-a-subdirectory

Also do note, that the /htdocs folder is not visible in the URL, so

my.domain/htdocs/hi

Is not the correct format, htdocs is not included in the url

4 Likes

Thanks - yes I know - I was referring to the location via ftp. But good information for anyone else reading this.

Oh sorry :joy:

in index.php put this

<?php header("Location: example.php"); ?>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.