contao/import — Issue #3522: Besserer www-Rewrite
Author: importer
Created: 2011-11-29 21:44:07+00:00
State: open
Labels: Feature, framework

Nur ein kleiner Optimierungsvorschlag für die .htaccess

Dieses Rewrite-Regel funktioniert mit allen Domains (& Subdomains) "out of the box".

```
# check for www. at the beginning
RewriteCond %{HTTP_HOST} !^www\. [NC]

# match all domain elements
RewriteCond %{HTTP_HOST} ^((?:(?>[a-z\-]+)\.)+(?>[a-z]+)) [NC]

# rewrite with condition match %1
RewriteRule (.*) http://www.%1/$1 [R=301,L]
```

Man kann das auch nur auf die erste Domain-Ebene (oder einer festen Anzahl von Subdomain-Ebenen) beschränken in dem man den "+" Quantifier der ersten Non-Capturing-Group anpasst, z.B.

```
# match only second level domain
RewriteCond %{HTTP_HOST} ^((?:(?>[a-z\-]+)\.)(?>[a-z]+)) [NC]
```

```
# match only up to first subdomain level
RewriteCond %{HTTP_HOST} ^((?:(?>[a-z\-]+)\.){1,2}(?>[a-z]+)) [NC]
```

```
# match only first and second subdomain level
RewriteCond %{HTTP_HOST} ^((?:(?>[a-z\-]+)\.){2,3}(?>[a-z]+)) [NC]
```

Related issues: #3249

--- _Originally created by backbone on October 6th, 2011, at 05:04pm (ID 3522)_