多域在apache2上重定向非www和https

时间:2018-09-23 15:44:05

标签: apache .htaccess https debian apache2

我有一个带有WordPress Multisite的VPS。

我几乎没有指向主目录的域,但是我看到一些配置,但我做错了什么,但不确定在哪里...

VPS配置: 阿帕奇2 让我们加密https

apache2.conf默认为AllowOverride All

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

可用网站: default.conf

<VirtualHost *:80>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =main.domain 
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent
</VirtualHost>

可用网站: other.domain.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/
ServerAlias other.domain

    <Directory />
            Options FollowSymLinks
            AllowOverride all
    </Directory>
    <Directory /var/www/html/>
            Options FollowSymLinks
            AllowOverride all
            Order allow,deny
            allow from all
    </Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =other.domain
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent
</VirtualHost>

.htaccess

# Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value max_execution_time 300
php_value max_input_time 300

我尝试了很多解决方案,以至于我弄乱了一些配置。

我只想将WordPress多站点内容保留在.htaccess中,并将所有重定向都移到配置文件中。

我想将www转换为非www重定向,并将http转换为https,但是在特定域-配置文件上,我做错了什么? 已经尝试过:

https://stackoverflow.com/questions/9945655/apache-redirect-http-to-https-and-www-to-non-www

0 个答案:

没有答案