1

OK so... I have the following URL which works on my site:

http://my_domain.net/w/mRD3nKkM

The rewrite for this in the root of my site is:

RewriteRule ^([w])/(\w+)$ res/$1/response.php?id=$2 [L]

Simple stuff and works a treat. Now I want to redirect any traffic that hits that URL unencrypted to go over https, like below:

https://my_domain.net/w/mRD3nKkM 

So I put another .htaccess file within the res/w/ folder conatining the following:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} ^/response.php$
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^(.*)$ https://my_domain.net/w/$1 [R,L]

To my miind this should work, but doesn't.

To be clear, I have the following URL rewrite working:

http://my_domain.net/w/mRD3nKkM

and I would like it to look like this:

https://my_domain.net/w/mRD3nKkM

Thanks

4

1 回答 1

1

你应该http => https在做内部转发之前处理。以下应该为您工作:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTPS} off
RewriteRule ^w/.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

RewriteRule ^(w)/(\w+)/?$ res/$1/response.php?id=$2 [L,NC]
于 2013-09-03T16:18:14.297 回答