为啥我的 .htaccess 仅针对 https / ssl 不将 uri 路径重定向到 index.php?
Posted
技术标签:
【中文标题】为啥我的 .htaccess 仅针对 https / ssl 不将 uri 路径重定向到 index.php?【英文标题】:Why are uri paths not redirected to index.php by my .htaccess only for https / ssl?为什么我的 .htaccess 仅针对 https / ssl 不将 uri 路径重定向到 index.php? 【发布时间】:2014-03-21 17:55:12 【问题描述】:当 URL 具有必须重定向到 index.php 以进行正确路由的 uri 路径时,我只会收到 404 错误。
例子:
200 => https://localhostcl.idinteractive.co/
200 => http://localhostcl.idinteractive.co/
200 => http://localhostcl.idinteractive.co/login
404 => https://localhostcl.idinteractive.co/login (this should be redirect by the htaccess below to index.php). Why is it not?
浏览器说...
在此服务器上找不到请求的 URL。上的链接 引用页面似乎是错误的或过时的。请告知作者 关于错误的那个页面。
Apache 错误日志说...
[2014 年 2 月 19 日星期三 12:59:06] [错误] [客户端 127.0.0.22] 文件没有 存在:C:/DATA/IDInteractive/IDdashboard/dev/cl/login
.htaccess
AddDefaultCharset UTF-8
AddHandler x-mapp-php6 .php
<IfModule mod_rewrite.c>
RewriteEngine On
DirectoryIndex index.php
RewriteBase /
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_URI !(^wwwroot.*)
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]
#RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.html
</IfModule>
http-vhost.conf
NameVirtualHost *:80
Listen *:80
<VirtualHost 127.0.0.22:80>
<Directory "C:/DATA/IDInteractive/IDdashboard/dev/cl">
AllowOverride All
Options +Includes
Allow from all
</Directory>
ServerAdmin xxx@taylormadetraffic.com
DocumentRoot "C:/DATA/IDInteractive/IDdashboard/dev/cl"
ServerPath "C:/DATA/IDInteractive/IDdashboard/dev/cl"
ServerName localhostcl.idinteractive
ServerAlias localhostcl.idinteractive.co
ErrorLog "logs/idinteractive-error.log"
CustomLog "logs/idinteractive-access.log" combined
AddType application/x-httpd-php .php
AddType application/x-mapp-php5 .php
AddHandler application/x-mapp-php5 .php
AddHandler php-cgi .php
AddHandler server-parsed .html
AddHandler application/x-httpd-php .php .htm
</VirtualHost>
httpd-ssl.conf
<IfModule ssl_module>
NameVirtualHost *:443
Listen *:443
<IfModule mime_module>
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
</IfModule>
SSLPassPhraseDialog builtin
SSLMutex default
<VirtualHost 127.0.0.22:443>
DocumentRoot "C:/DATA/IDInteractive/IDdashboard/dev/cl"
ServerName localhostcl.idinteractive
ServerAlias localhostcl.idinteractive.co
ServerAdmin xxx@taylormadetraffic.com
ErrorLog "logs/idinteractive-ssl-error.log"
<IfModule log_config_module>
CustomLog "logs/idinteractive-ssl-access.log" combined
</IfModule>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
<FilesMatch "\.(cgi|shtml|pl|asp|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/xampp/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
CustomLog "logs/ssl_request.log" "%t %h %SSL_PROTOCOLx %SSL_CIPHERx \"%r\" %b"
AddType application/x-httpd-php .php
AddType application/x-mapp-php5 .php
AddHandler application/x-mapp-php5 .php
AddHandler php-cgi .php
AddHandler server-parsed .html
AddHandler application/x-httpd-php .php .htm
</VirtualHost>
</IfModule>
Windows 主机文件:
127.0.0.22 localhostcl.idinteractive.co
【问题讨论】:
login
是目录吗?
【参考方案1】:
您还需要在您的 ssl vhost 中包含 <Directory>
容器:
<Directory "C:/DATA/IDInteractive/IDdashboard/dev/cl">
AllowOverride All
Options +Includes
Allow from all
</Directory>
否则AllowOverride
不会在 SSL 虚拟主机中设置为 All
,但它在非 SSL 虚拟主机中设置。
【讨论】:
以上是关于为啥我的 .htaccess 仅针对 https / ssl 不将 uri 路径重定向到 index.php?的主要内容,如果未能解决你的问题,请参考以下文章
如何仅在 HTTPS 上从 .htaccess 设置 HSTS 标头 [关闭]
htaccess 仅针对域根将 index.html 重定向到 index.php