dsrjs86444 2015-01-02 06:31
浏览 61
已采纳

Apache 2.4 + Codeigniter Urls在HTTP上工作但不在HTTPS上工作

I have a codeigniter application with dynamic wildcard subdomains that are secured using ssl. My issue is that only the home links are working with https i.e

https://sub1.site.com -- works

https://sub1.site.com/register -- gives a 404 error saying the file cannot be found on port 443

however sub1.site.com/register -- works

I have used this snippets to configure my site .

this is my config.php for the dynamic subdomains

   if (isset($_SERVER['HTTP_HOST']))
 22 {
 23   $protocol = ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://');
 24   $config['base_url'] = $protocol.$_SERVER['HTTP_HOST'];
 25   $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
 26 }
 27 else
 28 {
 29    $config['base_url'] = '';
 30 }

Then I have also used this to enable htaccess in apache2.conf

     AccessFileName .htaccess
154 
155 <Directory /var/www/>
156         Options  FollowSymLinks
157         AllowOverride All
158         Require all granted
159 </Directory>

and finally here is my htaccess file

<IfModule mod_rewrite.c>
  2     RewriteEngine On
  3     RewriteBase /
  4     #this is to allow no indexes
  5     Options All +Indexes
  6         #www is not a subdomain 
  7         #RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  8         #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  9 
 10     #Removes access to the system folder by users.
 11     #Additionally this will allow you to create a System.php controller,
 12     #previously this would not have been possible.
 13     #'system' can be replaced if you have renamed your system folder.
 14     RewriteCond %{REQUEST_URI} ^system.*
 15     RewriteRule ^(.*)$ /index.php?/$1 [L]
 16 
 17     #When your application folder isn't in the system folder
 18     #This snippet prevents user access to the application folder
 19     #Submitted by: Fabdrol
 20     #Rename 'application' to your applications folder name.
 21     RewriteCond %{REQUEST_URI} ^application.*
 22     RewriteRule ^(.*)$ /index.php?/$1 [L]
 23 
 24     #Checks to see if the user is attempting to access a valid file,
 25     #such as an image or css document, if this isn't true it sends the
 26     #request to index.php
 27     RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
 28     RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
 29     RewriteRule ^(.*)$ index.php?/$1 [L]
 30 
 31 </IfModule>
 32 
 33 
 34 <IfModule !mod_rewrite.c>
 35     # If we don't have mod_rewrite installed, all 404's
 36     # can be sent to index.php, and everything works as normal.
 37     # Submitted by: ElliotHaughin
 38 
 39     ErrorDocument 404 /index.php
 40 </IfModule>
 41 AddType image/x-windows-bmp bmp

my virtual host configuration in /etc/apache2/sites-available is as follows

1 NameVirtualHost *:80
  2 <VirtualHost x.x.x.x:80>
  3         SSLEngine On
  4         SSLCertificateFile /etc/ssl/wild/STAR_site_mobi.crt
  5         SSLCertificateKeyFile /etc/ssl/wild/myserver.key
  6         SSLCertificateChainFile /etc/ssl/wild/site.ca-bundle
  7         
  8         ServerAdmin webmaster@localhost
  9         DocumentRoot /var/www
 10         ServerName www.site.mobi
 11         ServerAlias site.mobi
 12         Redirect / https://www.site.mobi
 13         
 14         <Directory />
 15                 Options FollowSymLinks
 16                 AllowOverride ALL
 17         </Directory>
 18         <Directory /var/www/>
 19                 Options +Indexes +FollowSymLinks +MultiViews
 20                 AllowOverride ALL
 21                 Require all granted
 22         </Directory>
 23         ErrorLog ${APACHE_LOG_DIR}/error.log
 24 
 25         # Possible values include: debug, info, notice, warn, error, crit,
 26         # alert, emerg.
 27         LogLevel warn
 28         
 29         CustomLog ${APACHE_LOG_DIR}/access.log combined
 30 
 31 </VirtualHost>
 32 <VirtualHost *:80>
 33         #SSLEngine On
 34         #SSLCertificateFile /etc/ssl/wild/STAR_site_mobi.crt
 35         #SSLCertificateKeyFile /etc/ssl/wild/myserver.key
 36         #SSLCertificateChainFile /etc/ssl/wild/STAR_site_mobi.ca-bundle
 37         
 38         ServerAdmin webmaster@localhost
 39         DocumentRoot /var/www
 40         ServerName site.mobi
 41         ServerAlias *.site.mobi
 42         Redirect / https://*.site.mobi
 43         <Directory />
 44                 AllowOverride ALL
 45         </Directory>
 46 </VirtualHost>
 47 <VirtualHost x.x.x.x:443>
48         #SSLEngine On
 49         #SSLCertificateFile /etc/ssl/wild/STAR_site_mobi.crt
 50         #SSLCertificateKeyFile /etc/ssl/wild/myserver.key
 51         #SSLCertificateChainFile /etc/ssl/wild/STAR_site_mobi.ca-bundle
 52 
 53         ServerAdmin webmaster@localhost
 54         DocumentRoot /var/www
 55         ServerName site.mobi
 56         ServerAlias *.site.mobi
 57         <Directory />
 58                 Options FollowSymLinks
 59                 AllowOverride ALL
 60         </Directory>
 61         <Directory /var/www/>
 62                 Options +Indexes +FollowSymLinks +Multiviews
 63                 AllowOverride ALL
 64                 Require all granted
 65 
 66         </Directory>
 67 
 68 </VirtualHost>
  • 写回答

1条回答 默认 最新

  • doukanhua0752 2015-01-03 01:39
    关注

    vhost does not looks ok to me. ssl engine on should be in :443 And instead of reading .htaccess rules on the fly every page,include them once in /var/www/ Directory Try somenting like this:

    <VirtualHost *:80>
           DocumentRoot /var/www
           ServerName www.site.mobi
           ServerAlias site.mobi
           Redirect permanent / https://site.mobi
    </VirtualHost>
    
    <VirtualHost x.x.x.x:443>
           #ServerAdmin webmaster@localhost
           DocumentRoot /var/www
           ServerName site.mobi
           ServerAlias *.site.mobi
           <Directory />
                   Options FollowSymLinks
                   AllowOverride ALL
           </Directory>
           <Directory /var/www/>
               Order allow,deny
               Allow from all
               Require all granted
               Options +FollowSymLinks -Indexes
               RewriteEngine On
    
               # Instead of reading .htaccess rules on the fly every page,
               # Include them once, now, in this directory context
               AllowOverride None
    
    
              #Removes access to the system folder by users.
              #Additionally this will allow you to create a System.php controller,
              #previously this would not have been possible.
              #'system' can be replaced if you have renamed your system folder.
              RewriteCond %{REQUEST_URI} ^system.*
              RewriteRule ^(.*)$ /index.php?/$1 [L]
    
              #When your application folder isn't in the system folder
              #This snippet prevents user access to the application folder
              #Submitted by: Fabdrol
              #Rename 'application' to your applications folder name.
              RewriteCond %{REQUEST_URI} ^application.*
              RewriteRule ^(.*)$ /index.php?/$1 [L]
    
              #Checks to see if the user is attempting to access a valid file,
              #such as an image or css document, if this isn't true it sends the
              #request to index.php
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule ^(.*)$ /index.php?/$1 [L]
           </Directory>
           SSLEngine On
           SSLCertificateFile /etc/ssl/wild/STAR_site_mobi.crt
           SSLCertificateKeyFile /etc/ssl/wild/myserver.key
           SSLCertificateChainFile /etc/ssl/wild/site.ca-bundle
    </VirtualHost>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试