Handling subdomains and https with .htaccess

旧巷老猫 提交于 2019-12-02 21:10:35

问题


In the .htaccess example below, if someone types in a URL like the following...

http://mysite.com/ricks-motorcycles

...it will automatically load the page from x.com's subdirectory under public_html called "ricks-motorcycles". This technique is called Proxy Throughput.

RewriteEngine On
RewriteRule ^ricks-motorcycles/(.*)$  http://x.com/ricks-motorcycles/$1 [P,L]

This is great, but how do I handle two other situations:

(1) Someone wanting https instead of http.

(2) Someone wanting...

http#//ricks-motorcycles.mysite.com/

...instead of...

http#//mysite.com/ricks-motorcycles/

(Switch # with : above because StackOverflow was blocking me from posting.)


回答1:


You can qualify your rewrites with a RewriteCond:

RewriteEngine On

RewriteCond %{HTTPS} =on
RewriteRule ^ricks-motorcycles/(.*)$ https://example.com/ricks-motorcycles/$1 [P,L]

RewriteCond %{HTTP_HOST} =ricks-motorcycles.mysite.com
RewriteRule ^(.*)$ http://example.com/ricks-motorcycles/$1 [P,L]

For more information, see the mod_rewrite documentation.



来源:https://stackoverflow.com/questions/1054458/handling-subdomains-and-https-with-htaccess

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