ФорумПрограммированиеPHP для идиотов → Как сделать поддомены?

Как сделать поддомены?

  • XoxMa

    Сообщения: ? Репутация: N Группа: Кто попало

    Spritz 8 мая 2008 г. 14:12

    Вообщем нашёл я скрипт, и как обычно - не работает. Может я что-то делаю не так?
    Хочу чтобы вы протестили или написали другой способ. Я знаю, там есть какие-то DNS, но они мне не нужны.
    Вот ссылка на скрипт - http://www.1go.dk/webhotel/subdoms.phps
    И FAQ:

    About the script

    Subdomains is a PHP script that adds numerous sub domains to your website. When the script has been installed, all you need to do to create a new sub domain is a make a new directory. I.e., if you create the directory http://yoursite.com/newdir then the following sub domain will automatically be added: http://newdir.yoursite.com.



    Features

    No need to edit any files when you want a new sub domain – whenever you create a new directory it will automatically function as a sub domain.
    Works even if the visitor enters "www."; in front of the URL: http://www.dir.yoursite.com and http://dir.yoursite.com will both redirect the visitor to http://yoursite.com/dir.
    Case insensitive: http://Dir.YourSite.com, http://DIR.YOURSITE.COM, and http://dir.yoursite.com will all redirect the visitor to http://yoursite.com/dir.
    Can be used with or without frames. If you use frames, the location bar in the browser will not change – i.e., if the visitor enters http://dir.yoursite.com, the location bar will still show this URL when the visitor has been redirected to the new location (http://yoursite.com/dir). If you decide not to use frames, the location bar will change from http://dir.yoursite.com to http://yoursite.com/dir.




    Requirements

    Before you get too excited, you should know that only a minority of all web hosts meet the requirements of this script. To use Subdomains, you need a web site account with the following features:
    Your own domain, i.e. yoursite.com.
    Wildcarded DNS. The script will not function without this feature. To check if your web host offers wildcarded DNS, you can perform the following test: Start your browser, pick a random word (i.e. "asdf"), and enter your domain name with the random word in front of it like this: asdf.yoursite.com. If you can see the front page of your web site in your browser now, your web host offers wildcarded DNS. However, if the browser response is something like "unable to locate the server asdf.yoursite.com", then your web host does not offer wildcarded DNS, and you cannot use Subdomains (unless, of course, you move to a server that offers this feature).
    PHP (version 3 or later). Ask your web hosting company if you don't know if they offer PHP.
    .htaccess. In some cases it is necessary to edit the .htaccess file in order to make the script work. This means that your web host must provide you with the ability to use .htaccess files. If the name of the web server software is Apache, then it is very likely that you can use .htaccess files – but ask your web hosting company if you are unsure.




    Installing the script

    First you need to change the file name of your front page. The front page is the file that visitors to your web site see when they enter http://yoursite.com. The current name of this file is probably "index.html", "index.php", "default.html", or "home.html", but you need to change the name to something else, i.e. "welcome.html", "front_page.html", "page_1.html" or something similar.
    Load the script (index.php) into a plain text editor such as KEdit (Linux) or Notepad (Windows). Edit the variables at the top of the page.
    The $domain variable should be set to the name of your domain. Do not include "www.";. Do not include any slashes ("/"). Just write the domain name, i.e. "yourdomain.com". The $default_page variable should be set to the file name of the front page of your web site. I.e., if your front page is located at http://yourdomain.com/welcome.html, you should write "welcome.html" here. The $use_frames variable: If you want to use frames, write "yes" – otherwise write "no". Have a look at the features section of this README file and the FAQ if you don't understand the difference between redirection using frames and redirection without using frames.
    Use a FTP program to upload the index.php file to your web site account. The file should be placed in the document root (this means that you should be able to call the file by pointing your browser to http://yoursite.com/index.php). You don't need to chmod the script since it is not a CGI script.
    Now you can try it out. If it works, you're done. If it doesn't work, check the FAQ.
    When you want to create a new sub domain, just make a directory in your document root (i.e. http://yoursite.com/newdir). This will automatically work as a sub domain (http://newdir.yoursite.com). Remember that the name of the directory cannot include CAPITAL LETTERS. If you create a directory named "Newdir", the sub domain thing won't work. If you create a directory called "newdir", it will work.




    FAQ

    When I enter the URL to my web site, the browser shows a directory listing (a list of all files in the current directory).
    You need to add the following line to the .htaccess file:
    DirectoryIndex index.php index.html index.shtml index.htm

    See the .htaccess question in this FAQ if you don't know how to do this.

    When I enter the URL to my web site, the browser shows a white page with a lot of PHP code.
    You need to add the following lines to the .htaccess file:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php3 .php

    See the .htaccess question in this FAQ if you don't know how to do this.

    How do I edit the .htaccess file?
    Well, first of all you need to establish whether there's a .htaccess file in your document root or not. This can be done be performing the following test: Point your browser to http://yoursite.com/.htaccess (note the dot before "htaccess"). If you get a 404 error (File Not Found), there's no .htaccess file in your document root. However, if you get a 403 error ("Forbidden"), there's a .htaccess in your document root. If you don't have a .htaccess file, you will need to make one. Open a text editor, click "New" and write the necessary lines (the lines are shown elsewhere in this FAQ). You should not write anything else besides these lines – no HTML tags, no PHP tags, etc. When you're done writing the file, upload it to the server and place it in the document root. Perform the test above to make sure the file has been placed in the right location. If there's already a .htaccess file in your document root, all you need to do is load this file into a text editor and add the appropiate lines at the bottom of the file (the lines you need to write are shown elsewhere in this FAQ).

    What's the advantages and disadvantages of using frames when redirecting?
    There's one big advantage to using frames: The location bar in the browser does not change. I.e., if the visitor enters http://dir.yoursite.com, this URL will remain in the location bar even though the real location is http://yoursite.com/dir. If you don't use frames, the URL in the location bar will change to the actual location (http://yoursite.com/dir in this example). The disadvantage to using frames is the fact that the title of the page will not be shown. Instead, the location will be shown in the title bar. I.e., if the title of the index.html file at http://yoursite.com/dir is "My page", then this title will not be shown if you are using frames. Instead the following title will be shown: "yoursite.com/dir";. Another disadvantage of using frames is the fact that visitors cannot bookmark the sub pages of the main page.

    What's the difference between the sub domains generated by the Subdomains script and real sub domains?
    The price! "Real" sub domains are expensive. If you were to ask your web hosting company to create a sub domain for you, the company would have to change the web server configuration files as well as the DNS server setup. This will of course cost you a lot of money. And this is just the price of one sub domain! With Subdomains you can create as many sub domains as you want. However, "real" sub domains does have one big advantage which those created by the Subdomains script don't: With "real" sub domain, visitors to your web site can enter a URL like this: http://subdomain.yoursite.com/somedir/somepage.html. This will not work with the sub domains created by the script – only http://subdomain.yoursite.com will work. If the visitor enters the URL http://subdomain.yoursite.com/somedir/somepage.html, he/she will be redirected to http://yoursite.com/somedir/somepage.html.
  • adw0rd

    Сообщения: 22902 Репутация: N Группа: в ухо

    Spritz 8 мая 2008 г. 14:38, спустя 26 минут 13 секунд

    XoxMa™, залей себе на хостинг и включи полный вывод ошибок…
    adw/0
  • XoxMa

    Сообщения: ? Репутация: N Группа: Кто попало

    Spritz 9 мая 2008 г. 13:12, спустя 22 часа 33 минуты 33 секунды

    Я знаю, что все шибки должны выводиться в файл error_log, но там нет никаких ошибок, связанных с поддоменами.
  • megabit

    Сообщения: ? Репутация: N Группа: Кто попало

    Spritz 9 мая 2008 г. 13:54, спустя 41 минуту 59 секунд

    а может с делать в .htaccess


    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain.site.ru$
    RewriteRule ^(.*)$ http://site.ru/papka$1 [R=301,L]

    хотя фиг знает мож нето :)))
  • Ёлочник

    Сообщения: ? Репутация: N Группа: Кто попало

    Spritz 12 мая 2008 г. 8:08, спустя 2 дня 18 часов 14 минут

    Как раз в тему набрёл на статью: http://blog.dotfix.ru/2008-04-07/dinamicheskoe-sozdanie-subdomenov-nikakoy-magii/#more-477
  • XoxMa

    Сообщения: ? Репутация: N Группа: Кто попало

    Spritz 12 мая 2008 г. 11:25, спустя 3 часа 16 минут 49 секунд

    Большое спасибо.

Пожалуйста, авторизуйтесь, чтобы написать комментарий!