.htaccess / https 重定向,虚拟文件​​夹访问(有例外)

发布于 2024-08-09 19:04:01 字数 1203 浏览 6 评论 0原文

/* 这似乎是我 10 天前问过的另一个问题的重复 (.htaccess / 重定向到 https://www.example.com 和虚拟文件夹访问),但是 (a) 我没有收到对我对问题所做的更改的任何回复,并且(b)这里的这个问题是上述问题的一个更复杂的版本,我相信需要一个新的查询*/

我有一个具有以下实体的网站: example.com/index.html example.com/main.php example.com/SPECIAL/main.php 除此之外,我还有 example.com/images/、/css/ 等文件夹,脚本生成的 html 指向这些文件夹。

我需要 .htaccess 魔法来实现以下所有功能:

(a) 将用户从“example.com”永久重定向到“www.example.com”(301 内容)

(b) 将用户从 http://www.example.com 永久重定向到 https://www.example.com(301 内容)

(c) 访问 example.com/ 的用户当然应该看到 index.html,但如果他们输入
     example.com/ABCDEF OR
    ;  example.com/ABCDEF/
它们应该被重定向到 example.com/main.php?folder=ABCDEF
除非 ABCDEF 是一个真实的文件夹(如 /SPECIAL/、/images/、 /css/等)

(d) 如果用户尝试访问 example.com/REALFOLDER/(例如 /images/),他应该被重定向到 example.com/

(e) 所有这些都不应该干扰 example.com/index.html

的查看

抱歉,如果这听起来很复杂,但这正是我所需要的!

S

/* THIS would appear to be a duplicate of another question I had asked 10 days back (.htaccess / redirecting to https://www.example.com and virtual folder access), but (a) I didnt get any responses to the changes I made to the question, and (b) this question here is a more complex version of the above and I believe warrants a new query */

I have a site which has the following entities:
example.com/index.html
example.com/main.php
example.com/SPECIAL/main.php
besides the above, I have folders like example.com/images/, /css/, etc which the html generated by the scripts point to.

I need .htaccess magic for ALL of the below:

(a) permanently redirecting users from "example.com" to "www.example.com" (301 stuff)

(b) permanently redirecting users from http://www.example.com to https://www.example.com (301 stuff)

(c) users accessing example.com/ should, of course, see index.html, but if they type
     example.com/ABCDEF OR
     example.com/ABCDEF/
they should be redirected to example.com/main.php?folder=ABCDEF
EXCEPT when ABCDEF is a real folder (like /SPECIAL/, /images/, /css/, etc)

(d) If user tries to access example.com/REALFOLDER/ (eg /images/), he should just be redirected to example.com/

(e) All of this should not mess with the viewing of example.com/index.html

Sorry if this sounds complex, but thats exactly what I need!

S

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2024-08-16 19:04:01

尝试这些规则:

# (a) and (b)
RewriteCond %{HTTP_HOST} =example.com [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
# (d)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . / [L,R]
# (c)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ main.php?folder=$1 [L]

Try these rules:

# (a) and (b)
RewriteCond %{HTTP_HOST} =example.com [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
# (d)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . / [L,R]
# (c)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ main.php?folder=$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文