RewriteEngine On
RewriteCond %{THE_REQUEST} \s(\S+)\.html
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*)$ $1@%1? [L]
GET /file.html HTTP/1.1/file.htmlФлаг [L] останавливает текущую итерацию обработки запроса. Однако если запрос был изменен теми RewriteRule, которые все-таки успели отработать, Apache запустит цикл обработки запроса заново с первого RewriteRule.
map $args $_at {
default "@";
"" "";
}
server {
location ~ ^(.+)\.html$ {
return 301 $1$is_args$args;
}
location / {
try_files $uri $uri$_at$args.html $uri/ /index.php?$args;
} $uri@$args.html нормально работает для/groups/6e6a8e0ba4/posts?groupHash=cwkqcxch&sort=author&start=21&view=outline+?/post?postTypeName=General+Product+Question&sort=az&view=full&start=2401rewrite ^ http://site.com/posts/c0a323fc07 redirect;rewrite ^ http://site.com/posts/c0a323fc07 permanent;location /comment/ {
rewrite ^/comment/375/?$ http://site.com/posts/c0a323fc07 permanent;
rewrite ^/comment/2772/?$ http://site.com/posts/76d68d4d9d permanent;
} а если в странице нет знака @ то по запросу site.com/posts/db23e8225b надо отдать страницу /posts/db23e8225b.html но это не для всех файлов. т.е. както сделать условие, что сперва проверяется наличие страницы с html, а затем идет обращение к index.php . потому что сейчас она так же отдает 404
http://site.com/posts/db23e8225btry_files $uri $uri$_at$args.html $uri/ /index.php?$args;/posts/db23e8225b.html.http://site.com/posts/db23e8225b?a=b, то идёт обращение к файлу /posts/db23e8225b@a=b.html location / {
rewrite ^(.*)$ /%1 redirect;
rewrite ^(.*)$ /$1.html break;
if ($query_string ~ "^(.+)$"){
rewrite ^(.*)$ /$1@%1? break;
}
}