htaccess重写强制https适用于网站的某些部分,但不适用于其他部分(htaccess rewrite forcing https works on some parts of site but not others)
我试图强制https在网站的某些页面和子目录,但它只适用于子目录,而不是页面。
这是我目前的htaccess文件:
Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^/?admin/ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,QSA] RewriteRule ^/checkout.php https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,QSA]
第一次重写有效,但第二次没有。 因此,如果我导航到www.domain.com/admin/,它将重定向到https://domain.com/admin/,但如果我导航到www.domain.com/en/checkout.php,则不会重定向到https版本。 这是为什么? 我记得只使用不同的页面而不是checkout.php使用相同的确切代码,然后就可以了。 我无法在该页面上测试它,因为我不再拥有它,但我实际上是复制粘贴重写规则并更改了页面的名称。
I'm trying to force https on certain pages and subdirectories of the site, however it only works for subdirectories, not pages.
This is my current htaccess file:
Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^/?admin/ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,QSA] RewriteRule ^/checkout.php https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,QSA]
The first rewrite works, but the second one doesn't. So if I navigate to www.domain.com/admin/ it will redirect to https://domain.com/admin/ but if I navigate to www.domain.com/en/checkout.php it doesn't redirect to the https version. Why is that? I remember using the same exact code only with a different page instead of checkout.php and it worked back then. I can't test it on that page because I don't have it anymore but I literally copy-pasted the rewrite rule and changed the name of the page.
原文:https://stackoverflow.com/questions/17681063
最满意答案
不确定为什么要使用数组来保存最后一个id,但问题是你没有初始化id;
var id; id++; //NAN
正如您所看到的,Javascript非常丢失 ,您可以向数组添加属性并在未定义的变量上使用运算符而不会出现任何错误。 在你的情况下,
$scope.todos.id = 0;
在初始化数组后应该解决问题。但最好将最后一个id保存在另一个变量中,并且它不需要在范围内,只需
var lastId = 0;
和lastId++
就足够了。Not sure why you are using an array to hold the last id, but the problem is that you are not initializing the id;
var id; id++; //NAN
Javascript is very lose as you can see, you can add properties to arrays and use operators on undefined variable without getting any error. In your case,
$scope.todos.id = 0;
right after initializing the array should fix the problem.But it would be better to hold the last id in another variable, and it doesn't need to be in the scope, just
var lastId = 0;
andlastId++
is enough.
相关问答
更多-
我面临同样的问题。 Specyfying ID手动似乎是唯一的解决方案。 如果你不需要任何东西(如JavaScript)的ID,但希望它只是唯一的,你可以为他们生成GUID: <%: Html.RadioButton("", UserType.Primary, Model == UserType.Primary, new { id="radio" + Guid.NewGuid().ToString()}) %> 更优雅的解决方案是在HtmlHelper上创建自己的扩展方法,从视图中分离ID创建逻辑。 就像 ...
-
如何在Hibernate中通过其子项的ID-s删除项目?(How to delete items by ID-s of their child item in Hibernate?)[2021-08-05]
您可以继续使用.setParameter但您需要使该值扩展一个Collection(如ArrayList)而不是使用数组类型。 也许只是改成: public int deleteItemsByContentIds(Long[] contentIds) { EntityManager em = getEntityManager(); int result = em.createQuery( "delete from PlaylistItem where artContent.id in ... -
通过AngularJS中JSON数组的id获取特定的JSON对象(Get specific object by id from array of objects in AngularJS)[2024-01-17]
唯一的方法是遍历数组。 显然,如果您确定结果是按照id排序的,您可以进行二进制搜索 The only way to do this is to iterate over the array. Obviously if you are sure that the results are ordered by id you can do a binary search -
正如其他人所提到的, json_encode将确定某些东西是数组还是对象。 很多复杂性来自于您将用户ID设置为每个元素的键的方式。 1, 'name' => 'Employee 1', 'office' => 'Office 1'], ['id' => 2, 'name' => 'Employee 2', 'office' => 'Office 1'], ['id' => 3, 'name' => 'Employee 3' ...
-
如何通过angularjs中的id数组对对象列表进行排序?(How do I sort my list of objects by an id array in angularjs?)[2023-05-25]
如果您需要使用序列数组的给定id的任意顺序,则可以使用具有排序顺序的对象。 array = [{ id: 2613, name: "Aula 01", section: 989 }, { id: 2614, name: "Aula 02", section: 989 }, { id: 2616, name: "Aula 04", section: 989 }, { id: 2617, name: "Aula 05", section: 989 }, { id: 2615, name: "3 - Aula 0 ... -
最简单的方法是创建一个函数来生成随机字符和唯一索引以保证唯一性,如果插入因重复而失败,请再试一次。 CREATE FUNCTION random_char() RETURNS CHAR(1) RETURN ELT(FLOOR(1 + (RAND() * 62)), 'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', 'A', ...
-
最简单的方法是删除WHERE子句。 这将返回所有行。 SELECT name FROM table 如果你想要一些“魔法”值,你可以使用你可以在现有查询中使用的ID,它将返回所有行,我认为你运气不好。 虽然你可以使用这样的东西: SELECT name FROM table WHERE id = IFNULL(?, id) 如果提供值NULL ,则将返回所有行。 如果您不喜欢NULL尝试以下查询,如果提供值-1 ,将返回所有行: SELECT name FROM table WHERE id = IF ...
-
对象到angularjs中的数组(Object to array in angularjs)[2023-03-27]
这将为您提供仅包含有效用户的数组: $scope.validuser = $scope.users.filter(function(user) { return user.sport_id === 3; }); This will give you an array containing only the valid users: $scope.validuser = $scope.users.filter(function(user) { return user.sport_id === 3; ... -
1.使用JavaScript for ... in循环: var bookingData = { "roomList": [{ id: 1, roomCategory: "Single", number: 2 }, { id: 2, roomCategory: "Double", number: 1 }] }; var roomListData = {}; for(var i in bookingData.roomList) { roomL ...
-
不确定为什么要使用数组来保存最后一个id,但问题是你没有初始化id; var id; id++; //NAN 正如您所看到的,Javascript非常丢失 ,您可以向数组添加属性并在未定义的变量上使用运算符而不会出现任何错误。 在你的情况下, $scope.todos.id = 0; 在初始化数组后应该解决问题。 但最好将最后一个id保存在另一个变量中,并且它不需要在范围内,只需var lastId = 0; 和lastId++就足够了。 Not sure why you are using an arr ...