【发布时间】:2017-04-09 03:17:51
【问题描述】:
尝试使用 https,但是当我在 .htaccess 中使用以下内容时,出现重定向问题错误
这是我的.htaccess中的内容
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
#Uncomment lines below when uploading to the live server
RewriteCond %{HTTP_HOST} !^(www\.)example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ index.php [QSA,L,NC]
#Uncomment lines below when uploading to the live server
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg|png|tif|js|css|xls|xlsx|zip|rar|pdf|ods|ots)$ - [F]
请帮忙
【问题讨论】:
-
如果可以,请考虑定义重定向的方法,如果可以避免使用 .htaccess,并且在 virtualhsot 中定义大部分内容会更好。大多数时候重定向到 ssl 涉及定义适当的虚拟主机和一个简单的重定向/hostname,request_filename 检查然后转到 index.php,都可以为单个 Fallbackresource 指令删除,等等...
标签: apache .htaccess mod-rewrite https http-redirect