Htaccess redirect and its configuration

.htaccess (, /home/user/sitename/) . («») - . .htaccess (), - .

.htaccess. , CMS, , .htaccess .

htaccess redirect




.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 redirect files




, , , - . , , , , .





.htaccess

.htaccess . , /home/user/sitename_html/.htaccess , - , - .htaccess, .

, .htaccess, , , . , , , .htaccess .

.htaccess PHP vhost.conf php.ini , .

, .htaccess . ; .

htaccess redirect




.htaccess:

, .htaccess. , , .

301:

, , , . .htaccess 301 , URL- ( URL-) .

302:

302 , URL- , . Apache .

, .htaccess, , . 301.

redirect via htaccess




.htaccess.

, .htaccess .

, - Apache (mod_rewrite). .

Windows :

  1. .http.conf. , Apache.

  2. http.conf, , - .

  3. #LoadModule rewrite_module modules/mod_rewrite.so ( #).

  4. , <directory> <directory/> Options All AllowOverride All </directory>.

  5. "AllowOverride None" "AllowOverride All".

  6. - .

Linux :

sudo a2enmod rewrite

, . , Apache :

sudo service apache2 restart

htaccess 301 redirect page




.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.

  • () : , $1. , , , , URL.

htaccess redirect does not work




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

redirect to another htaccess domain




, 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.




All Articles