【发布时间】:2015-01-26 10:44:26
【问题描述】:
我有一个网站可以工作并尝试通过 htaccess 进行重定向几天。我已经在网上搜索并找到了很好的作品,尤其是在这个网站上,但是尽管我尝试了几乎所有的可能性,但我无法实现我想做的事情。
我的需要是将所有站点重定向到非 www http,包括 https,除了一个文件。假设重定向
http://www.example.com/.../....php?a=...
https://www.example.com/.. ./....php?a=...
https://example.com/.../....php?a=...
到
http://example.com/.../....php?a=...
但是,只有一个特定文件
http://www.example.com/.../theSpecificFile.php?a=...
https: //www.example.com/.../theSpecificFile.php?a=...
http://example.com/.../theSpecificFile.php?a=. ..
应重定向到
https://example.com/.../theSpecificFile.php?a=...
为此,我编写了许多 htaccess 文件,但在每种情况下,我都无法满足我的需求。例如在最后一个htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
ErrorDocument 404 http://example.com/404.php
#force https for certain pages
RewriteCond %{HTTPS} !=on
RewriteRule ^(theSpecificFile\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#redirect www.example.com to example.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
通过这个 htaccess 文件,
当我尝试 https://www 时,我得到 Unsecure or Untrusted connection(我正在从另一种语言翻译,希望它可能是真正的翻译)与 ssl_error_bad_cert_domain
当我尝试访问 theSpecificFile.php 时,我得到错误定义“infine loop”(我再次希望这可能是一个真实的翻译)。
这真的让我很沮丧,所以,任何帮助都将不胜感激。
提前致谢
【问题讨论】:
标签: php apache .htaccess mod-rewrite redirect