.htaccess (, /home/user/sitename/) . («») - . .htaccess (), - .
.htaccess. , CMS, , .htaccess .
.htaccess
.htaccess , , . .htaccess . , , plain text (.txt).
- Windows "", .
- Mac TextEdit. «» TextEdit « » « ». TextEdit .htaccess.
- Linux , – (vi, nano), ( , gedit).
htaccess.txt. .htaccess, . , , , .
.htaccess
.htaccess , . , HTML- (/var/www/vhosts/example.com/httpdocs/), .
, .htaccess.
FTP-, . FTP – . .
.htaccess
, - .htaccess, .
.htaccess , Test:
Test
#
DirectoryIndex page.html page.txt ...
, , ( ).
, , , - . , , , , .
.htaccess
.htaccess . , /home/user/sitename_html/.htaccess , - , - .htaccess, .
, .htaccess, , , . , , , .htaccess .
.htaccess PHP vhost.conf php.ini , .
, .htaccess . ; .
.htaccess:
, .htaccess. , , .
301:
, , , . .htaccess 301 , URL- ( URL-) .
302:
302 , URL- , . Apache .
, .htaccess, , . 301.
.htaccess.
, .htaccess .
, - Apache (mod_rewrite). .
Windows :
.http.conf. , Apache.
http.conf, , - .
#LoadModule rewrite_module modules/mod_rewrite.so ( #).
, <directory> <directory/> Options All AllowOverride All </directory>.
"AllowOverride None" "AllowOverride All".
- .
Linux :
sudo a2enmod rewrite
, . , Apache :
sudo service apache2 restart
.htaccess .
1. .htaccess:
Redirect 301 /retiredpage.html http://www.example.com/newpage.html
2. ( ):
RedirectMatch 301 ^/olddir/ http://www.yourdomain.com/newdir/
3. .htaccess WWW:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.sitename\.com$ [NC]
RewriteRule ^(.*)$ http://sitename.com/$1 [L,R=301]
4. WWW:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.samplehost\.com$ [NC]
RewriteRule ^(.*)$ http://www.samplehost.com/$1 [L,R=301]
5. .htaccess ( ):
RedirectMatch 301 ^(.*)$ http://www.yoursite.com
6 .htaccess- HTML PHP-:
RedirectMatch 301 (.*)\.html$ http://www.examplesite.com$1.php
7. HTTPS:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=permanent,L]
8. URL- :
<IfModule mod_rewrite.c>
RewriteMap lc int:tolower
</IfModule>
httpd.conf -. .htaccess :
RewriteEngine On
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]
9. . , . , URL. . , URL, :
: ^folder1$ «folder1» .
. : , (, a, B, 3);
* : , ;
: ^uploads.*$ «uploads2009», «uploads2010» ;
^.*$ « ». , , URL.
404 Not Found
, . , .htaccess.
404 Not Found, . URL, . , ? , , .
URL- (, http://example.com/folder1//file.html - ), .
URL,
URL- , , , , .
.htaccess , . .htaccess . , FTP .htaccess, .
, HTML PHP-. , , .
[L] , URL- .
.htaccess
, URL- .htaccess, Apache. , , .htaccess.
vhost (httpd.conf), /etc/apache2/sites/sitename.
:
<VirtualHost *:80>
ServerName www.mysite.com
ServerAlias www.mysite.com
Redirect / http://mysite.com
</VirtualHost>
, , WWW.
WWW, , .
<VirtualHost *:80>
ServerName anywebsite.com
ServerAlias anywebsite.com
Redirect / http://www.anywebsite.com
</VirtualHost>
Apache, . , , htaccess.