【问题标题】:.htaccess / redirecting to https://www.example.com and virtual folder access.htaccess / 重定向到 https://www.example.com 和虚拟文件夹访问
【发布时间】:2009-10-21 16:06:58
【问题描述】:

我有一个域 example.com。每当键入以下内容之一时,我希望用户被重定向到 https://www.example.com

  • http://example.com
  • http://www.example.com
  • https://example.com

我还需要将访问/asdf(或/asdf/)的人重定向到/index.php?folder=asdf

我在第一部分找到了一些代码示例,但对于它们的有效性一直存在争议。


编辑:(需要更多帮助!:))

【问题讨论】:

  • 嗯 - 我想我应该在这里发布我的插件查询...... :) [下面是对 Gumbo 的回应]

标签: .htaccess https url-rewriting


【解决方案1】:

试试这些mod_rewrite 规则:

RewriteEngine on

RewriteCond %{HTTP_HOST} !=www.example.com [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

RewriteCond $1 !=index.php
RewriteRule ^([^/]+)/?$ index.php?folder=$1 [L]

但我建议您只允许一种 URL 表示法,即带有或不带有斜杠的一种。

【讨论】:

  • 嗨,Gumbo - 它的第一部分效果很好,但对于第二部分,我需要更多帮助。我希望所有访问“www.example.com”的用户都能访问“index.html”文件,但任何访问 example.com/abcde/ 的用户都被重定向到 example.com/subfolder=abcde。更复杂的是,我在 www.example.com/qwerty/ 有一个特殊的(但“真实的”)文件夹。不应更改其中的任何链接。谢谢!您之前的示例非常有帮助!
  • 哎呀 - 小错字:我的意思是说“任何访问 example.com/abcde/ 的人都会被重定向到 example.com/other.php?subfolder=abcde”
猜你喜欢
  • 2010-12-11
  • 1970-01-01
  • 1970-01-01
  • 2017-06-18
  • 1970-01-01
  • 2020-12-12
  • 2019-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多