How to route a particular URL to both http and https and others to https in Apache httpd

依然范特西╮ 提交于 2019-12-11 03:44:06

问题


I have a requirement to route a particular url, /gapp via http and https and other urls like /aapp, /bapp, /capp and the rest via https. I have succeded in routing everything to https but can't route /gapp to http. Below is my configuration:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^(gapp)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
</IfModule> 

# Should mod_jk send SSL information to Tomcat (default is On)
JkExtractSSL On

# What is the indicator for SSL (default is HTTPS)
JkHTTPSIndicator HTTPS

# What is the indicator for SSL session (default is SSL_SESSION_ID)
JkSESSIONIndicator SSL_SESSION_ID

# What is the indicator for client SSL cipher suit (default is SSL_CIPHER)
JkCIPHERIndicator SSL_CIPHER

# What is the indicator for the client SSL certificated (default is SSL_CLIENT_CERT)
JkCERTSIndicator SSL_CLIENT_CERT

# Send everything for context /examples to worker named worker1 (ajp13)
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

JkMount /aapp aapp 
JkMount /bapp/* bapp

JkMount /capp capp 

JkMount /gapp gapp 
JkMount /gapp/* gapp 

In simple words, I want to be able to do these:

http://example.com/gapp/
https://example.com/gapp/

How do I accomplish this?


回答1:


I believe you are looking for the same answer as this: .htaccess - htaccess redirect 4 specific pages

If you want to access everything other then a few urls on https and http, you would be better not to redirect however just make a rewrite condition for the URLs and if they match then redirect them to https:

#force https for certain pages
RewriteCond %{REQUEST_URI} !^/gapp
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R]


来源:https://stackoverflow.com/questions/25803626/how-to-route-a-particular-url-to-both-http-and-https-and-others-to-https-in-apac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!