server {
listen 127.0.0.1:80;
server_name localhost;
root /home/localhost/public_html/public;
index index.php;
log_not_found off;
access_log logs/localhost-access.log main;
charset utf-8;
location / {
try_files $uri $uri/ @php;
}
location @php {
rewrite ^/(.*) /index.php?url=$1;
}
location ~ /\. { deny all; }
location = /favicon.ico { }
location = /robots.txt { }
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9071;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
RewriteRule ^([0-9]+)$ index.php?id=$1 [L,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/?$ index.php?id=$1&city=$2 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.html$
RewriteRule ^(.*)$ index.php [L]
RewriteEngine On
RewriteRule ^(learn-html5)/(basic|overview)$ /$1/lesson/index.php?id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]{0,7})$ /go?id=$1 [L]
IndexIgnore .* *.php *.zip css js fonts img
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/myFolder/(css|js|fonts|img)/(.*)$ [NC]
RewriteRule ^ /myFolder/.%1/%2 [QSA,L]
RewriteRule ^([0-9]+)_(.*)/$ list.php?cat=$1 RewriteRule ^([0-9]+)_(.*)/([0-9]+)/$ list.php?cat=$1&page=$3
(.*)
означает любое количество любых символов.^([0-9]+)_(.*)/$
совпадает с 123_text/
и 123_text/345/
. RewriteRule ^([0-9]+)_(.*)/([0-9]+)/$ list.php?cat=$1&page=$3
RewriteRule ^([0-9]+)_(.*)/$ list.php?cat=$1
Первому RewriteRule передается путь от того места, где находится .htaccess, до запрошенного файла.
^test/(first|second|third)$
должно быть ^(first|second|third)$
<VirtualHost>
, а в .htaccess запрос будет проходить через все RewriteRule снова и снова, до тех пор, пока он не перестанет меняться.RewriteEngine On
RewriteRule ^(first|second|third)$ index.html [END]
RewriteRule ^(.+)$ 404.html [END]
RewriteCond %{HTTP_HOST} ^(www\.)?italy\.domainname\.com$ [NC]
RewriteRule ^contacts$ http://www.domainname.com/contacts?country=Italy [R=301,L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+)\.(domainname\.com)$ [NC]
RewriteRule ^(contacts)$ http://www.%2/$1?country=%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+)\.(domainname\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%2/$1?country=%1 [R=301,L]
RewriteCond %{HTTP_COOKIE} (?:^|;\s*)city=([^;]+)
RewriteCond "%1 moskva=url1 omsk=url2 orsk=url3" "^(\S+) .*?\1=(\S+)"
RewriteRule ^ /%2 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} old.ru
RewriteCond %{REQUEST_URI} !^/yandex_3457472в87f2рecd\.html
RewriteRule (.*) http://new.ru/ [R=301,L]
RewriteRule ^games/([^/]*)
RewriteRule ^games/finished/?$ index.php?do=games&t=finished [L]
RewriteRule ^games/live/?$ index.php?do=games&t=live [L]
RewriteRule ^games/shudle/?$ index.php?do=games&t=shudle [L]
RewriteRule ^games/shift/?$ index.php?do=games&t=shift [L]
RewriteRule ^games/([^/]*)/?$ index.php?do=games&date=$1 [L]