简体   繁体   English

.htaccess HTTPS重定向而不更改url

[英].htaccess HTTPS redirect without changing url

I have a main domain mydomain.com and a subdomain m.mydomain.com , both are SSL secured. 我有一个主域mydomain.com和一个子域m.mydomain.com两者均受SSL保护。

When I access the subdomain m.mydomain.com I want to be redirected on mydomain.com/mobile.php/nb without changing the url...so the url must remain m.mydomain.com 当我访问子域m.mydomain.com时,我希望在mydomain.com/mobile.php/nb上进行重定向,而无需更改网址...因此,该网址必须保留为m.mydomain.com

Here is what I came up: 这是我的想法:

RewriteEngine on  
RewriteCond %{HTTP_HOST} ^m\.mydomain\.com$ [OR]  
RewriteCond %{HTTP_HOST} ^www\.m\.mydomain\.com$  
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$  
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$  
RewriteRule ^(.*)$ "https\:\/\/mydomain\.com\/mobile\.php\/nb$1" [R=301,L]  

It redirects me right but it doesn't keep the subdomain url address. 它会正确地重定向我,但不会保留子域的网址。

All the solutions I've found works only if the sites are not secured(http). 我发现的所有解决方案仅在站点不安全(http)的情况下才有效。

It can, but shouldn't be done via the .htaccess file. 它可以但不应通过.htaccess文件完成。
This is normally done wihtin your vhost config file 这通常是在您的vhost配置文件中完成的

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://secure.example.com/
</VirtualHost>

<VirtualHost _default_:443>
    ServerName secure.example.com
    DocumentRoot /usr/local/apache2/htdocs
    SSLEngine On
    # etc...
</VirtualHost>

Source: https://wiki.apache.org/httpd/RedirectSSL 资料来源: https : //wiki.apache.org/httpd/RedirectSSL

The mod-rewrite R flag performs an external redirection of urls from old location to the new one. mod-rewrite R标志执行url从旧位置到新位置的外部重定向。 If you do not want to redirect your subdomain remove the R=301 flag from your RewriteRule and use an absolute path instead of the full url as Rewrite destination. 如果您不想重定向子域,请从RewriteRule中删除R=301标志,并使用绝对路径而不是完整URL作为重写目标。

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?m\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[ 0- 9a -zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0- 9]{ 32 }\.txt(?:\Comodo\DCV)?$
RewriteRule ^(.*)$ /mobile.php/nb/$1 [L]

This will internally redirect www.m.domain.com or m.domain.com to /mobile.php/nb/ . 这将在内部将www.m.domain.comm.domain.com重定向到/mobile.php/nb/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM