Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 在htaccess RewriteCond中使用多个URL_Apache_.htaccess - Fatal编程技术网

Apache 在htaccess RewriteCond中使用多个URL

Apache 在htaccess RewriteCond中使用多个URL,apache,.htaccess,Apache,.htaccess,我在.htaccess文件中使用以下代码来防止https提供某些URL。如何修改此代码以包含其他URL?例如,我也不希望从https加载关于页面。添加一个类似于“职业链接”的额外行不起作用 <IfModule mod_rewrite.c> RewriteEngine On # Go to https if not on careers RewriteCond %{SERVER_PORT} =80 RewriteCond %{THE_REQUEST} !/careers/[\s?]

我在.htaccess文件中使用以下代码来防止https提供某些URL。如何修改此代码以包含其他URL?例如,我也不希望从https加载关于页面。添加一个类似于“职业链接”的额外行不起作用

<IfModule mod_rewrite.c>
RewriteEngine On
# Go to https if not on careers
RewriteCond %{SERVER_PORT} =80 
RewriteCond %{THE_REQUEST} !/careers/[\s?] [NC,OR]
RewriteCond %{THE_REQUEST} !/capital/[\s?] [NC,OR]
RewriteCond %{THE_REQUEST} !/summer/[\s?] [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

# Go to http if you are on careers
RewriteCond %{SERVER_PORT} !=80 
RewriteCond %{THE_REQUEST} /careers/[\s?] [NC,OR]
RewriteCond %{THE_REQUEST} /capital/[\s?] [NC,OR]
RewriteCond %{THE_REQUEST} /summer/[\s?] [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]
</IfModule>

重新启动发动机
#如果不是在事业上,请转到https
RewriteCond%{SERVER_PORT}=80
重写cond%{THE_REQUEST}/职业/[\s?][NC,或]
重写cond%{THE_REQUEST}/大写/[\s?][NC,或]
重写cond%{THE_REQUEST}/summer/[\s?][NC]
重写规则^(.*)$https://www.example.com/$1[R,L]
#如果您正在从事职业,请转到http
重写cond%{SERVER\u PORT}=80
重写cond%{THE_REQUEST}/careers/[\s?][NC,或]
重写cond%{THE_REQUEST}/capital/[\s?][NC,或]
重写cond%{THE_REQUEST}/summer/[\s?][NC]
重写规则^(.*)$http://www.example.com/$1[R,L]

更好地使用正则表达式替换并最小化代码:

<IfModule mod_rewrite.c>
RewriteEngine On
# Go to https if not on careers
RewriteCond %{SERVER_PORT} =80 
RewriteCond %{THE_REQUEST} !/(careers|capital|summer)/[\s?] [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

# Go to http if you are on careers
RewriteCond %{SERVER_PORT} !=80 
RewriteCond %{THE_REQUEST} /(careers|capital|summer)/[\s?] [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]
</IfModule>

重新启动发动机
#如果不是在事业上,请转到https
RewriteCond%{SERVER_PORT}=80
重写cond%{THE_REQUEST}/(职业|首都|夏季)/[\s?][NC]
重写规则^(.*)$https://www.example.com/$1[R,L]
#如果您正在从事职业,请转到http
重写cond%{SERVER\u PORT}=80
重写cond%{THE|u REQUEST}/(careers | capital | summer)/[\s?][NC]
重写规则^(.*)$http://www.example.com/$1[R,L]

您可以指定多个
RewriteCond
,并在必要时使用
[或]
标志(否则使用隐式and,这意味着它们必须全部匹配)。您可以向我展示一个如何使用OR标志的示例吗?请先尝试一下。(您只想将其用于正匹配。)我尝试在URL行的末尾(NC标志之后)放置一个[OR],但它不起作用。如果您需要使用多个标志,它们将放在逗号分隔的括号中,
[NC,或]
(说真的,文档中提到了这一点,您已经将其用于您的
重写规则了……)