.htaccess - 子域到子文件夹 .htaccess 的 RewriteRule
问题描述
我正在尝试完成以下任务:
- 对 https 的非 http 强制 -有效
- www 强制非 www -作品
- 从子文件夹 (/web) 加载的网站 -有效
- test.example.com 加载不同的子文件夹 (/test) - 不起作用
4、不行,满足条件去/web。无法理解如何将其更改为 /test
我使用的 .htaccess 代码:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteRule ^(.*)$ /test/$1 [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteRule ^(.*)$ /example/web/$1 [L,NC,QSA]
解决方案
使用您显示的示例,请尝试在此处遵循 htaccess 规则文件。请确保在测试您的 URL 之前清除您的浏览器缓存。如果您有更多规则(除了显示的规则),请确保这些规则在这些规则之前。
RewriteEngine On
##Apply https to uris here..
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
##Apply non-www to uris here..
RewriteCond %{HTTP_HOST} ^(?:www\.)(example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
##Apply test to all uris here..
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test [NC]
RewriteRule ^(.*)/?$ example/web/$1 [L,NC,QSA]
##Apply test to all uris here..
RewriteCond %{HTTP_HOST} ^test\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test [NC]
RewriteRule ^(.*)/?$ www.example.com/test/$1 [L,NC,QSA]
推荐阅读
- nlp - 如何获取单词的依赖信息?
- postgresql - postgresql 中的临时表在会话结束时被删除。如何解决?
- python - iPython 内核和 Anaconda 环境
- vba - 从代码中删除 .select 的 VBA 问题
- javascript - 为什么我在 Passport JS 中的自定义回调不起作用?
- c++ - 如何从字符串中删除辅音?
- neural-network - 实施 CNN - 但图表是俄语
- android - Android Fragment 更换时重置
- php - 自定义 GET URL - str 替换 PHP
- ios - 我可以在测试模式下上传 Iphone App