我想修改 php -file以满足以下需求:
I want to modify a php-file to fulfill the following needs:
主域名:
- 将 http 重定向到 https
- 将非www 重定向至 www
- (对于主域名, www 是理想的,应该出现)
- Redirect http to https
- Redirect non-www to www
- (for main domain, www is desired and should appear)
子域名
- 重定向 http 至 https
- 将 www 重定向至非www
- (对于子域名, www 不是必需的,不应出现)
- Redirect http to https
- Redirect www to non-www
- (for subdomains, www is not desired and should not appear)
评论:子域名内容完全不同比主域(可能是 private.website 或 cloud.website )。 不只是一种不同的语言。因此,通过浏览器或CMS创建内部转发似乎没有用。它应该在最好的情况下通过 .hataccess 执行。
Comment: The subdomain has a completely different content than the main domain (could be private.website or cloud.website for example). It is not just a different language. Because of this, it seems not useful to create a internal forwarding via browser or CMS. It should be executed via .hataccess in best case.
推荐答案如果你正在使用PHP然后你需要写一些条件你没有给出子域的任何例子如果你要使用像de.example,uk.example这样的子域,那么你需要在帮助下重定向浏览器语言或者您也可以在访问者位置的帮助下进行
If you are using php then you need to write some conditions And you didn't give any example of sub domain IF you are going to use sub domain like de.example , uk.example then you need to redirect with the help of browser language Or you can also do it with the help of visitors locations
就像
<?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if($lang=="de") { header('Location: de.example/'); } ?>在这种情况下,您需要执行以下操作。
IN that case you need to do the followings.
1)http到https
1) http to https
RewriteCond %{HTTPS} !=on2)非www到www
2) non-www to www
RewriteCond %{HTTP_HOST} ^example$ [NC] RewriteRule (.*) www.example/$1 [R=301,L]3)www到非www
3) www to non-www
RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ %1/$1 [R=301,L]更多推荐
PHP:将主域重定向到https:// www,子域重定向到https://(不带www)
发布评论