Назад | Перейти на главную страницу

оптимизировать mod_rewrite в htaccess

У меня есть несколько условий mod_rewrite в .htaccess файл, который я время от времени расширял .. Но я не думаю, что он очень хорошо написан (я все еще новичок в mod_rewrite)

Иногда запросы заканчиваются бесконечными циклами

И вот только что добавил в файл SSL ..

При запросе https:// Я получаю ошибку 404 The requested URL /_secure/_secure/ was not found on this server. Каким-то образом он добавляет к пути лишний _secure?

.htaccess

#   redirect non-active subdomain to 'www'
RewriteCond %{HTTP_HOST}        !^(admin|api|demo|files|secure|www)\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$              http://www.domain.com [L,R=301]

#   put 'www' as subdomain if none is given
RewriteCond %{HTTP_HOST}        ^([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$              http://www.%1/$1 [L,R=301]

#   redirect to subdomain
RewriteCond %{HTTP_HOST}        ^www\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^_([^/]+)/          http://$1.%1/ [L,R=301]

#   start SSL on 'secure' subdomain if not started
#RewriteCond %{HTTPS}           !=on
#RewriteCond %{HTTP_HOST}       ^(secure)\.([^\.]+\.[^\.]+)$ [NC]
#RewriteRule ^(.*)$             https://%1.%2/$1 [L,R=301]

#   set language
RewriteCond %{REQUEST_URI}      ^/(da|en)/(.*)(\?%{QUERY_STRING})?$ [NC]
RewriteRule ^(.*)$              /%2?%{QUERY_STRING}&set_lang=%1 [L]

    #   subdomains
    # --------------------------------------------------------------------------------

    #   rewrite subdomain
    RewriteCond %{HTTP_HOST}        ^(admin|files)\.[^\.]+\.[^\.]+$ [NC]
    RewriteCond %{REQUEST_URI}      !^/_(admin|files)/ [NC]
    RewriteRule ^(.*)$              /_%1/$1 [L]

    #   rewrite 'secure' subdomain
    RewriteCond %{HTTP_HOST}        ^(demo|secure)\.[^\.]+\.[^\.]+$ [NC]
    RewriteCond %{REQUEST_URI}      !^/_secure/ [NC]
    RewriteRule ^(.*)$              /_secure/$1 [L]

    #   rewrite 'api' subdomain
    RewriteCond %{HTTP_HOST}        ^api\.[^\.]+\.[^\.]+$ [NC]
    RewriteCond %{REQUEST_URI}      !^/_api/ [NC]
    RewriteRule ^(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?             /_api/?%{QUERY_STRING}&v=$1&i=$2&k=$3&a=$4&t=$5&f=$6 [L]

#   translate SEO-friendly URL's
RewriteCond %{HTTP_HOST}        ^www\. [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.php$ [NC]
RewriteCond %{REQUEST_URI}      ^/([^/]*)/(?:([^/]*)/)?(?:([^/]*)/)?$ [NC]
RewriteRule ^(.*)$              /%1.php?%{QUERY_STRING}&subpage=%2&subsection=%3 [L]

Выяснил в чем дело ..

Я также добавил /_secure в DocumentRoot в httpd.conf