【发布时间】:2015-01-21 20:36:51
【问题描述】:
这是我的 htaccess
Options +FollowSymLinks
RewriteEngine On
# redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect to HTTPs for register
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} register
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
# don't do anything for images/css/js etc
RewriteRule \.(gif|jpe?g|png|css|js|woff|map)$ - [NC,L]
# redirect to HTTP for all other pages
RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !register
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [PT,L]
我有一个注册页面,其 URL 类似于 hxxp://www.example.com/index.php?register,并且 htaccess 正确重定向到 HTTPS。
现在我还希望我的购买页面 (hxxpp://www.example.com/buy)重定向到 HTTPS。此页面的真实 URL 是 hxxp://www.example.com/index.php?buy
请告诉我如何修改我的 htaccess 规则来满足这个需求。
【问题讨论】:
-
您的 URI 方案有点混乱。一方面你有
/index.php?register,另一方面你有/buy(内部重写为/index.php?products&type=buy。为什么不也有/register(重写为/index.php?register)? -
@JustinIurman:抱歉,这是 URL 中的拼写错误。固定。
标签: regex apache .htaccess mod-rewrite redirect