开发者

Force all pages to https in htaccess while maintaining current rules

I have the current htaccess in a folder sitting at http://www.mydomain.com/dev

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php [开发者_如何学编程L]

I tried changing my last line to:

RewriteRule ^(.*)$ https://www.mydomain.com/dev/index.php [L]

However, that didn't work and the site tossed up an ISE. Everything needs to run through mydomain.com/dev/index.php.


Easiest way to achieve this is to Create a seperate vhost on port 80 which redirects everything to https. Should look something like this in your Apache config:

<VirtualHost *:80>
    ServerName example.com

    # Force usage of SSL
    Redirect / https://example.com/
</VirtualHost>

<VirtualHost 127.0.0.1:443>
    DocumentRoot /var/www/vhosts/example.com/httpdocs
    ServerName example.com
</VirtualHost>

This should always redirect to the requested page's ssl equivalent, while keeping all your other rules intact. If you don't have access to the global Apache config (like on shared hosting machines), ask your host to apply the above to your vhost entry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜