的.htaccess / HTTPS重定向,有例外的虚拟文件夹的访问文件夹、重定向、htaccess、HTTPS

2023-09-02 09:45:24 作者:渡星河.

/ *这似乎是另外一个问题我问过10天回重复(http://stackoverflow.com/questions/1601876/htaccess-redirecting-to-https-www-mydomain-com-and-virtual-folder-access),但(一)我没有得到我的问题所做的更改任何响应,以及​​(b)在这里这个问题是一个比较复杂的版本以上,我相信值得一个新的查询* /

/* THIS would appear to be a duplicate of another question I had asked 10 days back (http://stackoverflow.com/questions/1601876/htaccess-redirecting-to-https-www-mydomain-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 */

我有一个网站,它具有以下实体: example.com/index.html example.com/main.php example.com/SPECIAL/main.php 除上述之外,我有这样example.com/images/文件夹/ CSS /等其中由脚本生成的HTML指向。

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.

我需要的.htaccess魔法全部的如下: (一)永久重定向用户example.com到www.example.com(301的东西) (二)永久重定向从 http://www.example.com 用户的 https://www.example.com (301东东) 当然(三)的用户访问example.com/应,见的index.html,但如果他们键入 或&NBSP example.com/ABCDEF;;   &NBSP&NBSP ;    example.com/ABCDEF/ 他们应该被重定向到example.com/main.php?folder=ABCDEF 除非ABCDEF是一个真正的文件夹(如/特/, /图像/,/ CSS /等) (四)如果用户试图访问example.com/REALFOLDER/(例如/图像/),他应该只是被重定向到example.com/ (五)所有这一切不应该乱用example.com/index.html

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=ABCDEFEXCEPT 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!

取值

推荐答案

请尝试以下规则:

# (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]