seesoe
seesoe

Reputation: 248

htaccess allow only numbers after a certain point with https

i attached my current htaccess file below, it currently makes all my urls www with trailing slash at the end and if it is on and only on /prepaid/ it will be https.

i am tring to extend this functionality, where i can also accept requests from /prepaid/refill/a 10 digit phone number and have it be https as well

i started by adding this line at the bottom, but how would i extend the https part to allow from this path as well?

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

the current code

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]

Upvotes: 2

Views: 1707

Answers (2)

anubhava
anubhava

Reputation: 785146

Have your full .htaccess like this:

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]

Upvotes: 1

Dreamm
Dreamm

Reputation: 141

to use https need write some ike this with regular expressions, you must be caution and be: \d+ - its only numberic characters

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule  ^prepaid/refill/(\d+)/?$        index.php?p=prepaid&phone=$1     [L]

Upvotes: 0

Related Questions