Htaccess function (forwarding of page and site)

The server is moved, and the page is moved, and the htaccess file achieves the page shown with mobility and the personal computer and can achieve separately worth easily by using this with a special file.

Feature of htaccess file

The htaccess file is a configuration file that controls the movement of the server, and each user is a special text file that can be set in each directory. There is no file name and the file only of the extension. It is necessary to up-load it by the FTP by the text mode for the text file.

The htaccess file influences the directory set up and the entire subdirectory under that.

According to the server. The htaccess file cannot be set up. It is not possible to put it in free homepage space a lot.

Distribution to mobile site where htaccess was used

It introduces the method of transferring the person who accessed it with the cellular phone making a mobile site and the site for the personal computer to a mobile page by the automatic operation. The following content in the root directory of the site. The htaccess file is put.

However, a usual page is not seen in the cellular phone as for this method. This is not so significant because seeing the page for the personal computer with the cellular phone becomes usual recently.

Reversely, I think that you should have it of a mobile, special page with the personal computer it is not possible to see.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^(DoCoMo|KDDI|DDIPOCKET|UP\.Browser|J-PHONE|Vodafone|SoftBank)
RewriteRule ^$ /m/ [R]

It flies to the file of "http://domain/m/"when user agent (HTTP_USER_AGENT) contains the character string of DoCoMo or KDDI when accessing it with the cellular phone.

"$" shows the end of the line in "^" of "^$" at the beginning of the line. In a word, there is nothing (http://domain), too. "[R]" is a meaning of forwarding.

There was no problem for me even though nothing is done excluding this. To the directory right under where the htaccess file is put

RewriteEngine Off

was described. You will put the htaccess file.

Method to fly to top page by using htaccess

There is a site sometimes written, "The link is prohibited directly besides top page" though have not used by me. I think that it is amusing to prohibit the direct link to the HTML file though it opens to the public on the homepage. However, I think that I become reference to do this by all means.

The above-mentioned. The control of access (A direct link prohibition and a direct link are prohibited) against files other than top page with a control of access (A direct link prohibition and a direct link are prohibited) that uses htaccess.

Next, when the file and the error that doesn't exist go out, (403: Forbidden, 404: File Not Found) applies the method of forwarding to a top page.

Method of not specifying address of top page by using htaccess

The address of top page usually becomes like index.htm and index.php, etc. , and it is usual that the address on the homepage writes "" and doesn't specify the index file. The address on the homepage need not be changed even if it changes from "index.htm" to "index.php" when it is this method.

However, even if the index file is not specified, the page to include the index file in the retrieval might be registered. In the point of SEO, this unites the address of top page to the one without the index file by using htaccess because it is undesirable. For instance, it is a method of the permanent forwarding when there is an access in "http://mydomain/index.php" by "http://mydomain/" 301.

Please note that this has the possibility of an infinite loop according to other settings. When the extension of the file is index.php or index.htm or index.html, the file name is removed. Severely specifying it finds the condition and the mistake is not found.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} (^.*/index\.php|^.*/index\.htm)
RewriteRule ^(.*)index\.(php|htm) /$1 [R=301,L]

It moved from the server by which the son was using the homepage to "" this time. Because file and the directory structure were almost the same, it did by .htaccess file paste direct function. It introduces it because it is very easy and was effective.

It is necessary to change all HTML file with 100 or more if this is not used, and to do the description forwarded to a new page. It makes it to all pages before the following descriptions are moved in a word. When the   place of "CONTENT=" is made "0", it becomes a permanent move. Besides, it might be considered move temporary.

<meta HTTP-EQUIV="Refresh" CONTENT="0;URL=*****.htm">

The one to do the same operation as this can be easily made from one .htaccess file. In a word, the following description was done. Htaccess file It   makes it for the directory of

Redirect permanent /
ErrorDocument 404
ErrorDocument 403

The purpose of the 2-3th line is also for (403:Forbidden, 404: File Not Found) to make forwarding done to a top page when file and the error that doesn't exist.

The description of this 2-3th line can be used even by a new address server. In a word, this 2-3th line was described in the directory of "" In the error that happens by it or less if you put htaccess file It is forwarded to the top page of ""

This method can fly to top page even when the HTML file name is changed or is deleted and is very convenient. Of course,This method cannot be used by the server that cannot use htaccess.

In general, when the thing where 404 redirecting file doesn't exist is told, it it is time when in no existence of the file, and doesn't describe from http as follows, and be 404. It redirects it to php. It doesn't become 404 in the above-mentioned method.

ErrorDocument 404 /404.php

It has experimented on the method of the description as Redirect 301.

Forwarding the file was tested by using the method (permanent move of the file) where it was described Redirect 301 by using htaccess. It described it in the htaccess file as follows. Let's confirm whether to be forwarded neatly by using View HTTP Request and Response Header in HTTP status code 301.

redirect 301 /earth.htm

The extension of the file has been changed from htm to php. (permanent move)

I. The method of operating the html file with PHP by using htaccess was used. To use the extension of the file that operates PHP with not only php but also htm and html. The following line is added to the htaccess file.

AddType application/x-httpd-php .htm .html

However, I came to feel the inconvenience such as becoming the error with different extension when the file was preserved with Expression Web3 when the html file was used indefinitely. Then, a permanent move of the file (301 moves) because the extension of all files was changed from htm to php. It set it with htaccess. After the extension of all htm had been changed to php, it set it as follows.

DirectoryIndex index.php index.html
RedirectMatch permanent (.*)\.htm$ $1.php

I am doing as follows now because I cannot use DirectoryIndex in Xrea and Coreserver.

RewriteCond %{THE_REQUEST} !(^.*/index\.htm)
RewriteCond %{THE_REQUEST} ^.*\.htm
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.htm /$1.php [R=301,L]

If file is not exist, it changes the (htm or html) extensions except (index.htm or index.htm) to php. In this case, the condition is neatly specified. It displays it even when it makes a mistake in the extension if the file of php exists. This is convenient.

Setting of server that can be accessed regardless of presence of www

The homepage was not able to be displayed by "http://www.mydomain/" by the homepage's being displayed in the server that I was using.

It came to make it to good when a variety of doing thinking did not come to being able the display neither. As the subdomain, it is www . It is a method of registering.

In a word, "www.mydomain" is registered in the subdomain by setting the domain, and forwarding is set. "http://mydomain/" However, this method confirmed becoming 302 moves.