Ich habe eine Website auf Craft CMS ausgeführt, ich bin mir nicht sicher, ob das Problem direkt mit dem CMS oder dem Server zu tun ist.Umleitung von www zu nicht-www funktioniert nicht
ich .htaccess bin mit jeder www URL einer nicht-www-Version neu zu schreiben
<IfModule mod_rewrite.c>
# (1)
RewriteEngine On
# (2)
Options +FollowSymlinks
# (3)
#Options +SymLinksIfOwnerMatch
# (4)
#RewriteBase/
# (5)
#RewriteOptions <options>
# (6)
RewriteCond %{HTTPS} =on
RewriteRule^- [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule^- [env=proto:http]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule^%{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Wenn ich domain.com/about
geben es funktioniert gut, aber wenn ich www.domain.com/about
geben sie die URL zu domain.com/index.php?p=about
ändert
In der Craft-Konfiguration habe ich 'omitScriptNameInUrls' => true,
aktiviert, was zusammen mit dem Folgenden die index.php von der URL entfernen sollte.
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
Hier ist die vhost-Datei.
<VirtualHost *:80>
ServerName domain.com
ServerAdmin [email protected]
DocumentRoot /var/www/
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Ich habe durch https://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost gesucht, aber kein Glück mit den Änderungen hatte. Ich benutze Ubuntu 16.04.1, Apache 2.4.18 und 7.0.8-0ubuntu0.16.04.3 Hosted auf Ubuntu.
Gibt es etwas, was ich testen kann, um zu sehen, ob ich die Umleitung für das www zum Nicht-www richtig funktioniert?
Ehrfürchtig, danke das hat funktioniert! Ich werde meine Htaccess-Datei neu organisieren. – zizther