2

我在下面附上了我当前的 htaccess 文件,它目前使我所有的网址 www 末尾带有斜杠,如果它打开并且仅在 /prepaid/ 上,它将是 https。

我正在尝试扩展此功能,我还可以接受来自 /prepaid/refill/ 10 位电话号码的请求,并将其设置为 https

我首先在底部添加了这一行,但是我将如何扩展 https 部分以允许从这条路径开始?

  RewriteRule  ^prepaid/refill/([0-9]+)/?$        index.php?p=prepaid&phone=$1     [L]

当前代码

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} !.                      [NC]
RewriteRule ^prepaid/?$     https://www.domain.com/prepaid/ [R=301,L]

RewriteCond %{HTTPS} on
RewriteRule ^prepaid/(.+)   http://www.domain.com/prepaid/$1    [R=301,L,QSA]


RewriteRule ^prepaid/?$                 index.php?p=prepaid                 [L]
RewriteRule ^prepaid/h2o-wireless/?$        index.php?p=prepaid&s=h2o           [L]
RewriteRule ^prepaid/net10-wireless/?$      index.php?p=prepaid&s=net10         [L]
RewriteRule ^prepaid/page-plus-cellular/?$  index.php?p=prepaid&s=pageplus      [L]
RewriteRule ^prepaid/red-pocket-mobile/?$   index.php?p=prepaid&s=redpocket     [L]
RewriteRule ^prepaid/simple-mobile/?$       index.php?p=prepaid&s=simplemobile  [L]
4

2 回答 2

1

像这样拥有完整的 .htaccess:

RewriteEngine On
RewriteBase /

# force www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]

# force HTTPS for /prepaid/ OR /prepaid/refill/([0-9]+)/
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} !.
RewriteRule ^prepaid(/refill/[0-9]+)?/?$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

# force HTTP for everything else
RewriteCond %{HTTPS} on
RewriteRule ^prepaid/(?!refill/[0-9]+).+$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

# internal rewrites
RewriteRule ^prepaid/?$                     index.php?p=prepaid                 [L,QSA,NC]
RewriteRule ^prepaid/h2o-wireless/?$        index.php?p=prepaid&s=h2o           [L,QSA,NC]
RewriteRule ^prepaid/net10-wireless/?$      index.php?p=prepaid&s=net10         [L,QSA,NC]
RewriteRule ^prepaid/page-plus-cellular/?$  index.php?p=prepaid&s=pageplus      [L,QSA,NC]
RewriteRule ^prepaid/red-pocket-mobile/?$   index.php?p=prepaid&s=redpocket     [L,QSA,NC]
RewriteRule ^prepaid/simple-mobile/?$       index.php?p=prepaid&s=simplemobile  [L,QSA,NC]
RewriteRule ^prepaid/refill/([0-9]+)/?$     index.php?p=prepaid&phone=$1        [L,QSA,NC]
于 2013-11-04T05:50:09.097 回答
0

使用 https 需要用正则表达式写一些 ike this,你必须小心并且是: \d+ - 它唯一的数字字符

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule  ^prepaid/refill/(\d+)/?$        index.php?p=prepaid&phone=$1     [L]
于 2013-11-03T21:49:20.067 回答