htacess:强制https和www如果不在localhost上(htaccess: forcing https and www if not on localhost)
我在我的localhost上工作,所以我在mod_rewrite规则中需要这个例外。 目前,我可以在不使用localhost时使用以下方法强制使用“www”:
# Force www, if not in localhost RewriteCond %{HTTP_HOST} !=localhost RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
现在,我还要强制https(我的整个网站将在https下)。 如何将此添加到我的htaccess?
我尝试像这样制作我的htaccess,但这也强制我的localhost上的https:
# Force https, if not in localhost RewriteCond %{HTTP_HOST} !=localhost RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # Force www, if not in localhost RewriteCond %{HTTP_HOST} !=localhost RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
更新1:我想我需要删除第一个
[R=301,L]
。更新2:如果我有这样的URL:
https://scripts.domain.com
:https://scripts.domain.com
,我不希望它成为:https://www.scripts.domain.com
:https://www.scripts.domain.com
。I work on my localhost so I need this exception in my mod_rewrite rule. Currently, I am able to force the "www" when not on localhost using the following:
# Force www, if not in localhost RewriteCond %{HTTP_HOST} !=localhost RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Now, I want to also force https (my entire site will be under https). How do I add this to my htaccess?
I tried making my htaccess like this, but this is forcing https on my localhost also:
# Force https, if not in localhost RewriteCond %{HTTP_HOST} !=localhost RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # Force www, if not in localhost RewriteCond %{HTTP_HOST} !=localhost RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
UPDATE 1: I think I need to remove the first
[R=301,L]
.UPDATE 2: If I have a URL like this:
https://scripts.domain.com
, I do not want it to become:https://www.scripts.domain.com
.
原文:https://stackoverflow.com/questions/12551235
最满意答案
在某些方面,C远不如C ++严格。
C ++中的函数签名
f()
表示不带参数的函数。 相反,在C语言中,它意味着一个函数,其参数未指定。 可以使用任意数量的参数调用它。要防止这种情况,请使用以下原型:
int f(void)
C is much less strict than C++ in some regards.
A function signature
f()
in C++ means a function without arguments, and a conforming compiler must enforce this. In C, by contrast, the behaviour is unspecified and compilers are not required to diagnose if a function is called with arguments even though it was defined without parameters. In practice, modern compilers should at least warn about the invalid usage.Furthermore, in function prototype declarations (without definition) in C, empty parentheses mean that the parameters are unspecified. It can subsequently be defined with any number of arguments.
To prevent this, use the following prototypeISO/IEC 9899 6.7.6.3/10:
int f(void)
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
C是一种自由形式的语言。 这意味着您可以通过多种方式进行格式化,仍然是法律程序。 例如一个声明 a = b * c; 可以写成 a=b*c; 或类似 a = b * c ; 所以当编译器看到这些行 temp = *a *a = *b; 它认为是意味着 temp = *a * a = *b; 这当然不是一个有效的表达式,编译器会抱怨而不是缺少的分号。 它无效的原因是因为a是指向结构的指针,所以*a * a试图将结构实例( *a )与指向结构( a )的指针相乘。 虽然编译器无法检测到丢失的分号,但它 ...
-
编译器看不到参数(Compiler can't see argument)[2023-03-26]
你的Hero总是有一把Sword 。 这意味着,在类实例化的时刻,在Hero::Hero构造函数开始运行之前,它必须有一个“默认” Sword 。 编译器抱怨它不知道如何制作这样的“默认” Sword 。 现在,有多种方法可以解决这个问题: 使用初始化列表 在构造函数的定义中,您可以指定对象的成员应如何初始化 ( 在实际的构造函数运行之前 )。 这与在构造函数体中为它们分配新值(在您的示例中发生)不同。 为此,在构造函数的签名后面跟随成员字段初始值设定项指定冒号(:),如下所示: Hero() : magi ... -
编译器知道它必须构造两者 。 它确实如此。 The compiler knows it must construct both. So it does.
-
如果你在linux系统上,使用的C库是glibc 。 GCC实际上并不提供C库实现,只提供头文件。 实际实现这些函数的定义是C库的职责。 在Linux上,有一些名为“共享库”的东西,它们被需要它的程序动态加载。 例如: ldd /usr/bin/gcc linux-vdso.so.1 (0x00007ffd9e9f8000) libm.so.6 => /lib64/libm.so.6 (0x00007ff9a35a6000) libc.so.6 => /lib64/libc.so.6 ...
-
它看起来像你的Visual C ++应用程序已经重载了operator new() 。 这通常会完成(使用您看到的其他参数),以便为每个内存分配添加调试和其他分析信息。 由于你得到的错误很简单,就像frame = new Cwktools4Frame; 我建议寻找重新定义“新”的宏或编译器级定义。 首先看看应该在调试特定的版本中。 I found the error: #ifdef __WXDEBUG__ #define new WXDEBUG_NEW #endif When I remove these ...
-
您是否将扩展类标记为静态? 即具有扩展方法的类必须标记为静态,扩展方法本身也必须是静态的。 public static class AExtensions : IA { public static void foo(this IA a) { a.foo(); } } Have you marked your extension class as static as well? i.e. The class with the extension method must be marke ...
-
在某些方面,C远不如C ++严格。 C ++中的函数签名f()表示不带参数的函数。 相反,在C语言中,它意味着一个函数,其参数未指定。 可以使用任意数量的参数调用它。 要防止这种情况,请使用以下原型: int f(void) C is much less strict than C++ in some regards. A function signature f() in C++ means a function without arguments, and a conforming compiler ...
-
我遇到了同样的问题。 我已经修改了Setting - > Compiler - > Global Compiler Settings - > Toolchain Execuatables (tab) 。 在那里,单击Program Files ,然后将C compiler gcc.exe命名为gcc.exe和C++ compiler到g++.exe 。 I faced the same problem. I have fixed out by going to Setting -> Compiler -> ...