Saturday, 15 March 2014

.htaccess - htaccess redirects (non-www to www, language default select, proper URL rewrite) -



.htaccess - htaccess redirects (non-www to www, language default select, proper URL rewrite) -

i need help written .htaccess file. did seek best doesn't work expected. want accomplish this:

first of all, if browser requests favicon.ico, gets 404, no exceptions, no rewrites/redirects (my current code still rewrites it, , returns 404), if subdomain admin., rewrite traffic /admin/ folder (leaving admin. in url), otherwise rewrite www. check if url has www. in front end of domain, if on 'subfolder' (ex.: domain.com/en/sub1/sub2/), otherwise redirect, check if language selected (en|sl), otherwise take default sl , redirect other requests index.php in root dir (with lang code included, ex.: www.domain.com/en/example/#selection, ?a=b doesn't need sent, won't utilize it)

current .htaccess:

options +followsymlinks -indexes rewriteengine on // works (still rewrites 2 times... can see in apache log) redirectmatch 404 favicon.ico // doesn't work @ redirect 404 /favicon.ico rewritecond %{http_host} ^admin\. [nc] rewriterule ^(.*)$ /admin/$1 [l] rewritecond %{http_host} !^www\. [nc] rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l] # check if lang. code provided otherwise select sl rewritecond %{request_filename} !-f rewritecond %{request_uri} !^/(sl|en)/ [nc] rewriterule ^(.*)$ /sl/$1 [r,l] # add together trailing slash if not found rewritecond %{request_filename} !-f rewritecond %{request_uri} !(.*)/$ rewriterule ^(.*)$ /$1/ [r,l] # process virtual links/directories rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ index.php/?$1 [qsa,l]

problems:

when accessing admin.domain.com 500 internal server error, favicon.ico isn't returned 404 @ first instance, everything else works, if have recommendation on how improve it, appreciate it.

solution:

i removed redirectmatch rule , go redirect 404 /favicon.ico, in add-on had add together everywhere rewritecond %{request_filename} !favicon.ico proper 404 response (without rewrite/redirection).

about admin subdomain: leaved same rules, have created additional .htaccess in /admin folder, sorts out traffic gets there.

admin.domain.com - 500 error

your admin rewrite matches broadly sends in infinite loop.

rewritecond %{http_host} ^admin\. [nc] rewriterule ^(.*)$ /admin/$1 [l]

try adding status rewritecond %{request_uri} !^/admin [nc] avoid loop (it never match if real request begins /admin.

rewritecond %{http_host} ^admin\. [nc] rewritecond %{request_uri} !^/admin [nc] rewriterule ^(.*)$ /admin/$1 [l] favicon.ico

both redirectmatch , redirect directive has 2 required arguments: regex/path , redirect url. status code optional. theoretically rule(s) redirectmatch 404 favicon.ico might interpreted "if path matches 404 redirect favicon.ico". suggest adding dummy url (that doesn't exist) directives, ala: redirect 404 /favicon.ico /dev/null.

.htaccess

No comments:

Post a Comment