A
A
Anna Bakurova2014-08-11 15:06:08
PHP
Anna Bakurova, 2014-08-11 15:06:08

How to make beautiful url with htaccess?

In general, there are a lot of links on this topic, but since I am a noob on the topic of administration, I spent a lot of time, but it didn’t work.
Task 1:
Redirect based on language
Code:

RewriteEngine on
# редирект на русскоязычную версию сайта для русских, украинских, белорусских и казахских браузеров
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP:Accept-Language} (ru|uk|by|kz) [NC]
RewriteRule .* http://propeller-app.com/pages/ru/index.html [R=301,L]
# редирект на англоязычную версию сайта для всех остальных языков
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule .* http://propeller-app.com/pages/en/index.html [R=301,L]

Task 2:
Shorten url from propeller-app.com/pages/en/index.html to propeller-app.com/index.html or propeller-app.com/en/index.html
Code:
DirectoryIndex /pages/ru/index.html

RewriteRule ^(|/)$ http://propeller-app.com/ru/index.html [L]

RewriteCond %{REQUEST_URI} !^(|/)
RewriteCond %{REQUEST_URI} !/pages
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule (.*) /pages/$1.html [L]
 
RewriteCond %{REQUEST_URI} !/pages
RewriteCond %{REQUEST_URI} .html$
RewriteRule (.*) /pages/$1 [L]

Task 3: - classic
remove .html .php etc.
Code:
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://site.ru/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]

- Everything works separately, but when I prescribe together (as soon as I didn’t write), it stops working
How to build these htaccess pieces to work. Or at least throw where to read

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DeFacto, 2014-08-12
@DeFacto

www.phpinfo.su/articles/practice/chpu_na_php.html

S
sat50, 2016-08-18
@sat50

Or you can also shorten the url on the service greemlink.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question