.htaccess用于https特定前缀网址的RewriteRule

时间:2013-07-13 05:11:47

标签: apache .htaccess mod-rewrite

我想在我的网站上的这些前缀网址上创建https://协议:

dream-portal.net/index.php?page=postratingspro

dream-portal.net/index.php?page=paypaltest

因此,此后URL中的任何内容都应包含https://协议。例如:

dream-portal.net/index.php?page=postratingspro;sa=blahblah;testing

我该怎么做?尝试了以下内容,但它没有将我的所有其他网址转换为网站上的http://。

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} = off
RewriteRule index.php?page=^(postratingspro|paypaltest)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# don't do anything for images/css/js (leave protocol as is)
RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]

# force http for all other URLs
RewriteCond %{HTTPS} = on
RewriteCond %{REQUEST_URI} !page=^/(postratingspro|paypaltest)\$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

我怎样才能做到这一点,我的代码出了什么问题呢?

1 个答案:

答案 0 :(得分:1)

用以下代码替换您的代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=(paypaltest|postratingspro)[&;,\s] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !(^|&)page=(paypaltest|postratingspro)([,;&]|$) [NC]
RewriteRule ^(index\.php)?$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]