我已经设法为www和非www(普通http)和https创建了有效的重定向,但是当将它们一起使用时,它将不再起作用。我有四个域,希望每个域都重定向到基本域,然后添加url参数。
尝试不同的版本时,立即获得当前结果:
www.example.fi -> redirects me to https://example.se/?lang=fi. OK
http://example.fi -> redirects me to https://example.se/?lang=fi OK
https://example.fi -> redirects me to https://example.se/?lang=fi OK
https://www.example.fi -> redirects me to https://example.se without the lang parameters. WRONG. It should take me to the same place as the other.
这是我的http虚拟主机:
<VirtualHost *:80>
ServerName www.example.fi
ServerAlias example.fi
DocumentRoot /var/www/html/dir
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / https://example.se/?lang=fi
</VirtualHost>
这是我的https:
<VirtualHost *:443>
ServerName www.example.fi
ServerAlias example.fi
DocumentRoot /var/www/html/dir
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/user/example.fi.pem
SSLCertificateKeyFile /home/user/example.fi.key
SSLCACertificateFile /home/user/intermediate.pem
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.fi$ [NC]
RewriteRule ^ https://example.se%{REQUEST_URI}/\?lang=fi [R=301,L]
如您所见,我希望不同的语言域使用language参数指向SE域。
如何修改我的代码,使其与https,http和www的所有可能变体一起匹配?
答案 0 :(得分:0)
在您的代码中
RewriteCond %{HTTP_HOST} ^example\.fi$ [NC]
RewriteRule ^ https://example.se%{REQUEST_URI}/\?lang=fi [R=301,L]
仅重写匹配项htt(s)://exemple.fi URL
没有^,它应该可以工作
RewriteCond %{HTTP_HOST} example\.fi$ [NC]
RewriteRule ^ https://example.se%{REQUEST_URI}/\?lang=fi [R=301,L]