.htaccess greift nicht

Schumiel

Lieutenant
Registriert
Jan. 2010
Beiträge
825
Hallo,

und zwar möchte ich eine .htaccess auf der Root-Ebene festlegen.

Code:
/

Die Webseite liegt aber im Verzeichnis

Code:
/html

indem die Root-Ebene der Webseite eben /html ist.

Nun bekommt meine Webseite die Konfigurationen der .htaccess nicht mit, weil sie ja außerhalb des Roots der Webseite liegt.

Wo und wie muss ich noch etwas konfigurieren?
 
Auf root Ebene kannst du das mit einer .ini steuern. Die .htaccess packst du in das html Verzeichnis.

Eine .htaccess könnte dann bspw. so aussehen

Code:
# pass the default character set
AddDefaultCharset utf-8

ErrorDocument 404 /404.html

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Header set Strict-Transport-Security: "max-age=604800; includeSubDomains; preload"


<ifModule mod_headers.c>
Header set Connection keep-alive
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "no-referrer"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Permitted-Cross-Domain-Policies "none"
Header always set X-XSS-Protection "1; mode=block"
</ifModule>

<IfModule mod_expires.c>
    ExpiresActive On
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf .ttf
    AddType application/x-font-opentype .otf
    AddType application/x-font-woff .woff
    AddType application/x-font-woff .woff2
    AddType image/svg+xml .svg
    AddType image/webp .webp
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-opentype "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/x-font-woff2 "access plus 1 year"
</IfModule>

<IfModule mime_module>
<files *.js>
ForceType text/javascript
</files>
 
<files *.css>
ForceType text/css
</files>
</IfModule>
 
<IfModule headers_module>
<IfModule deflate_module>
# Netscape 4.x
BrowserMatch ^Mozilla/4 no-gzip
# For browsers that pretend to be Mozilla4
BrowserMatch \b(MSIE|Safari) !no-gzip
# IE5.5 and 6.0 has bugs
BrowserMatch \bMSIE\s(5\.5|6\.0) no-gzip
# IE 6.0 after SP2 may not have gzip bugs!
BrowserMatch \bMSIE.*SV !no-gzip
# Sometimes Opera pretends to be IE6
BrowserMatch \bOpera !no-gzip
 
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/font-woff
AddOutputFilterByType DEFLATE application/font-woff2
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-opentype
 
Header append Vary User-Agent
</IfModule>
</IfModule>
 
<IfModule gzip_module>
mod_gzip_on Yes
 
mod_gzip_item_exclude reqheader "User-agent: Mozilla/4"
mod_gzip_item_include reqheader ^User-agent\:.*\b(MSIE|Safari)
mod_gzip_item_exclude reqheader ^User-agent\:.*\bMSIE\s(5\.5|6\.0)
mod_gzip_item_include reqheader ^User-agent\:.*\bMSIE.*SV
mod_gzip_item_include reqheader ^User-agent\:.*\bOpera
 
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.js$
mod_gzip_item_include file \.css$
 
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include mime ^text/css$
mod_gzip_item_include mime ^text/javascript$
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include mime ^application/x-javascript.*
</IfModule>
 
Es darf und soll keine .htaccess im Ordner /html geben. Das muss alles über die .htaccess auf / (Root) gesteuert werden.
 
Warum denn überhaupt mittels .htaccess? Alles was du dort konfigurieren kannst, kannst du auch direkt in einem Directory Block der Apache httpd Config eintragen, ganz ohne die Probleme und Risiken einer htaccess Datei.
 
  • Gefällt mir
Reaktionen: Anteru und FeelsGoodManJPG
Zurück
Oben