Forum Moderators: phranque

Message Too Old, No Replies

Make directory the domain root

         

rwilson

3:43 pm on Oct 4, 2011 (gmt 0)

10+ Year Member



I'm working on a site overhaul, and am trying to come up with the best way to migrate it from my test domain to the live domain without too many problems.

Even if just temporarily I want to put my new site files in a folder called "new-site" I want this folders content to display when you go to example.com instead of example.com/new-site/

Can I do this in .htaccess?

lucy24

9:35 pm on Oct 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can do anything in htaccess :) Almost.

But here you need to give more information. Two things in particular:

Are you only concerned with the single entry page? If the whole site is coded with relative links, and you start with a Redirect, then everything from there on is automatic. If you want it to work independently at every level, the RewriteBase is your friend. If you get it right it will work beautifully and transparently, but if you get it wrong it will be an unholy mess ;)

Do you want to Rewrite (user's address bar shows sitename.com/index.html although they are really at sitename.com/new-site/index.html) or Redirect (user's address bar shows where they "really" are)?

Third, tangential question: Are you sure you want to do it at all? If you leave out the redirecting or rewriting, then the only people who can get to /new-site/ are the ones who know it exists, so you've got time to work out the bugs before the spiders arrive. Wholly unintended mental picture there.

rwilson

10:47 pm on Oct 4, 2011 (gmt 0)

10+ Year Member



Your third point is a good one, I may want to test everything out while running the current site but, let's say I do want to do it. I would like to have it say "sitename.com/index.html" when it's really sitename.com/new-site/index.html

g1smd

1:30 am on Oct 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You will need something within the requested URL in order to signal that this is a URL request that should be rewritten, so that the rule can be crafted to rewrite only those requests, otherwise you will have to set things up such that ALL requests will be rewritten.

If you are testing a site you should put it on a test. or dev. subdomain and password protect it to stop searchengines indexing it.

lucy24

3:13 am on Oct 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are testing a site you should put it on a test. or dev. subdomain and password protect it to stop searchengines indexing it.

I'm currently doing something very similar to what rwilson describes: the "real" site files are one level up, inside a /new-site/ directory (not its real name, duh). There's a "dummy" index file substituting for the host's placeholder.* Auto-indexing is off, of course, so there's no way for robots to know that the /new-site/ directory exists. Unless they guess its name, which so far they haven't.


* It was recently updated to look vaguely like the real index file, with a text block saying that the site should be up and running by the end of the month. Fortunately I did not specify which month. But it would be nice if the Person In Charge responded to nagging before the domain name comes up for renewal. Sigh.

g1smd

7:19 am on Oct 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I never use "test site in a folder" because the .htaccess rules might need to be altered when the site is moved to the root. So, test site is in the root folder in the dev. or test. subdomain and the main site is in the root folder in the www. subdomain. The canonicalisation rules remove www for dev. and test. and add www. for bare example.com requests.

Finally, never link to or show "index.html" within a URL. The URL for a folder or for the index page in that folder ends with a trailing slash.

lucy24

9:15 am on Oct 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Finally, never link to or show "index.html" within a URL. The URL for a folder or for the index page in that folder ends with a trailing slash.

I know that, but my browsers and SubEthaEdit don't. Same goes for leading / instead of a ../relative link. So I can't just test changes on the fly; I have to go into MAMP and take it from there. And it only works for one domain at a time.

Incidentally, google seems to have made some kind of decision involving index.html files. Mine are variously listed as / or /index.html, but for any given file they only use one form or the other. Interesting.

rwilson

3:21 pm on Oct 5, 2011 (gmt 0)

10+ Year Member



I have my test site on a dev. subdomain on my own site with my own hosting, with potentially different server settings, .htaccess, ect... than the site I need to move it to. So what I was thinking is move everything over into a password protected directory on the new site and test it, then migrate it over to the "live" version of the site.

You will need something within the requested URL in order to signal that this is a URL request that should be rewritten, so that the rule can be crafted to rewrite only those requests, otherwise you will have to set things up such that ALL requests will be rewritten.


How would I go about doing that?

g1smd

3:40 pm on Oct 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You design the URLs so that they include a common element that says "rewrite" or they include a common element that says "do not rewrite". You have complete control over what the URLs that the site uses look like. It should be that these URLs are extensionless, have a parcular prefix, consist of a certain number of digits then a hyphen and some words, or whatever scheme you care to choose.