通过htaccess重定向,其中IP不是&&删除index.php(redirect via htaccess where IP is not && remove index.php)
我通常使用这个htaccess文件从ExpressionEngine中的URL中删除index.php
AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm AcceptPathInfo On Options -Indexes <IfModule mod_rewrite.c> RewriteEngine On Options +FollowSymLinks # Looks for files and directories that do not exist # and provide the segments to the index.php file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^/index.php RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC] RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
虽然这很有效,但在我们将此网站投入生产之前,我们通过此htaccess文件将所有流量指向给定的网址
RewriteEngine On RewriteBase / RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1 RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]
我自己的IP地址正在替换localhost调用,以便我可以访问该站点。
基本上我正在寻找的是这两个的组合,它将从我的URL中删除index.php,但仍然重定向其他人。
谢谢,史蒂文
I usually use this htaccess file to remove index.php from my URLs in ExpressionEngine
AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm AcceptPathInfo On Options -Indexes <IfModule mod_rewrite.c> RewriteEngine On Options +FollowSymLinks # Looks for files and directories that do not exist # and provide the segments to the index.php file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^/index.php RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC] RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
While that works great, before we move this site into production, we're directing all traffic to the given url to another via this htaccess file
RewriteEngine On RewriteBase / RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1 RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]
My own ip address is replacing the localhost call so that I can access the site.
Basically what I'm looking for is a combination of these 2 that will remove index.php from my URLs for me but still redirect everyone else.
Thanks, Steven
原文:https://stackoverflow.com/questions/13439519
最满意答案
代码的主要问题在于:
var subRow = myRow[z].lastChild;
这为某些行提供了文本节点对象,而不是
TD
元素。 并且文本节点没有innerHTML
属性。 由于其余的代码都适用undefined
,因此在计算中undefined
,并且出现问题。但是,由于您已经有了在addProduct函数中计算总和的代码,因此在removeBtn事件处理程序中几乎复制该代码是很遗憾的。
所以,我建议创建一个单独的函数,它将计算总数并显示它。 它将充分利用您的两个代码片段,避免上述问题:
function displayTotal() { // Code taken from the last part of addProduct: var toPay = document.getElementsByClassName("altogether"); var suma = 0; for (var n=0; n<toPay.length;n++) { // This condition is inspired by the removeBtn click handler: if (!toPay[n].parentElement.classList.contains("strike")) { suma = suma + parseFloat(toPay[n].innerHTML); } } // Only put the total at the end, not in the loop: howMuch.innerHTML = parseFloat(suma); }
虽然与您提到的问题无关,但我建议您在开始修改表之前进行任何验证检查。 检查空输入也是不够的。 您还应该检查输入是否为数字。
考虑到这一点,您的addProduct函数可能如下所示:
function addProduct() { // Before doing anything test the input is complete: if (quantityInput.value == "" || isNaN(quantityInput.value)) { alert("Please add quantity"); return; // and exit! } if (priceInput.value == "" || isNaN(priceInput.value)) { alert("Please add price"); return; // and exit! } var removeBtn = document.createElement("button"); removeBtn.innerHTML="Skreśl przedmiot"; var row = table.insertRow(1); var cell1 = row.insertCell(0); var cell2 = row.insertCell(1); var cell3 = row.insertCell(2); var cell4 = row.insertCell(3); var cell5 = row.insertCell(4); cell5.classList.add("altogether"); cell1.appendChild(removeBtn); cell2.innerHTML = productInput.value cell3.innerHTML = parseFloat(quantityInput.value); cell4.innerHTML = parseFloat(priceInput.value); cell5.innerHTML = parseFloat(quantity.value)*parseFloat(price.value); removeBtn.addEventListener("click", function(event){ this.parentElement.parentElement.classList.toggle("strike"); displayTotal(); }); // Code moved to function displayTotal(); }
所以你注意到displayTotal在两个地方被调用:添加产品之后,以及切换删除之后。 这样您就避免了代码重复。
这是更新的小提琴 。
还有什么可以改进的
如果您将购物车内容保存在变量(具有项目,价格和数量属性的对象的数组)中会更好。 这样您就不必读取HTML元素来找回这些数据,这不是很有效。
其次,您应该更好地为
textContent
分配值,而不是innerHTML
。 这样你就可以避免特殊字符的问题。 例如,如果您的产品名称中包含<
字符,则会看到部分产品未显示。 这是textContent
不具备的。最后,如果在真实应用程序中使用它,则购物车必须由服务器管理。 这是因为网页及其上的数字可以通过客户端软件,浏览器插件等轻松修改。因此它们不可信任。 所有检查都必须由服务器应用程序再次完成,该应用程序应该还有一个具有正确产品价格的数据库等。
The main issue with the code is in this line:
var subRow = myRow[z].lastChild;
That gives a text node object for some rows, not a
TD
element. And text nodes don't have aninnerHTML
property. Since the rest of your code works with that, you getundefined
in your calculations, and things go wrong.But, since you already have code that calculates the sum in the addProduct function, it is a pity to almost duplicate that code in the removeBtn event handler.
So, I would suggest to create a separate function, which will calculate the total and display it. It will take the best of both code pieces you have for that, avoiding the problem described above:
function displayTotal() { // Code taken from the last part of addProduct: var toPay = document.getElementsByClassName("altogether"); var suma = 0; for (var n=0; n<toPay.length;n++) { // This condition is inspired by the removeBtn click handler: if (!toPay[n].parentElement.classList.contains("strike")) { suma = suma + parseFloat(toPay[n].innerHTML); } } // Only put the total at the end, not in the loop: howMuch.innerHTML = parseFloat(suma); }
Although not related to the problem you mentioned, I would also suggest to do any validation checks before you start modifying the table. It is also not enough to check for empty input. You should also check that input is numerical.
Taking that into account, your addProduct function could look like this:
function addProduct() { // Before doing anything test the input is complete: if (quantityInput.value == "" || isNaN(quantityInput.value)) { alert("Please add quantity"); return; // and exit! } if (priceInput.value == "" || isNaN(priceInput.value)) { alert("Please add price"); return; // and exit! } var removeBtn = document.createElement("button"); removeBtn.innerHTML="Skreśl przedmiot"; var row = table.insertRow(1); var cell1 = row.insertCell(0); var cell2 = row.insertCell(1); var cell3 = row.insertCell(2); var cell4 = row.insertCell(3); var cell5 = row.insertCell(4); cell5.classList.add("altogether"); cell1.appendChild(removeBtn); cell2.innerHTML = productInput.value cell3.innerHTML = parseFloat(quantityInput.value); cell4.innerHTML = parseFloat(priceInput.value); cell5.innerHTML = parseFloat(quantity.value)*parseFloat(price.value); removeBtn.addEventListener("click", function(event){ this.parentElement.parentElement.classList.toggle("strike"); displayTotal(); }); // Code moved to function displayTotal(); }
So you notice that displayTotal is called at two places: after adding a product, and after toggling the removal. This way you have avoided code duplication.
Here is the updated fiddle.
What could be improved still
It would be better if you would keep the shopping cart contents in a variable (an array with objects that have item, price and quantity properties). That way you do not have to read the HTML elements to find back these data, which is not very efficient.
Secondly, you should better assign values to
textContent
and not toinnerHTML
. That way you will avoid problems with special characters. If for instance your product name has a<
character in it, you'll see part of it does not get displayed. This you will not have withtextContent
.Finally, if this were used in a real application, the shopping cart would have to be managed by the server. This is because a web page, and the numbers on it can easily be modified by the client software, browser add-ins, etc. So they cannot be trusted. All checks have to be done again by a server application, that should also have a database with the correct product prices, etc.
相关问答
更多-
购物清单/如何添加再次删除项目/ javascript [关闭](Shopping list/how to add again removed item/javascript [closed])[2024-01-27]
代码的主要问题在于: var subRow = myRow[z].lastChild; 这为某些行提供了文本节点对象,而不是TD元素。 并且文本节点没有innerHTML属性。 由于其余的代码都适用undefined ,因此在计算中undefined ,并且出现问题。 但是,由于您已经有了在addProduct函数中计算总和的代码,因此在removeBtn事件处理程序中几乎复制该代码是很遗憾的。 所以,我建议创建一个单独的函数,它将计算总数并显示它。 它将充分利用您的两个代码片段,避免上 ... -
从购物车中删除商品时,您将取消设置错误的值: unset($_SESSION['cart'][$remove]); 应该是你需要的一切。 } else { $_SESSION['cart'][$remove]; } 这一小段代码就是你需要从上面放置unset()调用的地方。 就目前来看,这个声明什么都不做。 You're unsetting the wrong values when removing items from the cart: unset($_SESSIO ...
-
购物清单列表项的Javascript程序文本未正确格式化(Shopping List Javascript program text of list items not formatting properly)[2022-01-07]
您必须将属性line-height添加到“li”元素样式: li { float: left; padding: 5px; margin-left: 92px; width: 324px; text-align: left; border-bottom: 1px solid #666; margin-bottom: 10px; /* like the image are 30px height + 16px padding, the line-height must be 4 ... -
jQuery中没有ignore()方法,所以它会在控制台中抛出错误。 因此,要么克隆tr并从克隆的对象中删除span ,然后获取文本或获取所有不包含span和获取文本的td。 $(document).ready(function() { $('.sweet-container').on('click', 'tr span', function(){ var removedname = $(this).closest('tr').clone().remove('span').text( ...
-
实际上在javascript中,var x = y; 表示将y的引用分配给x。 所以为了赋值,你必须使用var x = y.slice(); actually in javascript, var x=y; means assign reference of y to x. so in order to assign value you have to use var x=y.slice();
-
只需将输入对放入某个类的div中(此处为“pair”) var input='如果你可以发布一些代码或你发送给购物车类的数据会有所帮助,但这应该指向正确的方向: function add_cart_item(){ $data = $_POST; $id = $data['product_id']; //get new product id $qty = $data['quantity']; //get quantity if that item $cart = $this->cart->c ...
在Javascript中删除项目(Delete Item in Javascript)[2023-01-02]
首先,您必须将正确的product_id传递给删除功能。 此外,您需要知道要删除的元素,为此您可以发送按下了单击的当前元素,然后访问其父节点以将其删除。 您可以使用以下代码替换脚本: var qtyTotal = 0; var priceTotal = 0; var products = []; function addProduct() { var productID = document.getElementById("productID").value; ...问题的根源是 lines = str(myfile.read().split(', ')) shoppingList = [lines] 您将文件拆分为一个列表,从该列表中生成一个字符串,然后将该单个字符串添加到列表中。 shoppingList = myfile.read().split(', ') 足以做你想做的事: split为你创建一个列表。 您应该考虑从递归调用切换到循环:每个递归调用在构建新的堆栈帧时会增加开销,在这种情况下完全没有必要。 你现在拥有它的方式,每个新提示都有一个新的堆栈框架: ...可以有两种情况...... 该应用程序是多页的。 在这种情况下,您可以在另一个页面中对该类进行硬编码。 该应用程序是单页面的,该链接仅用于装饰目的。 在这种情况下,您可以阻止链接的默认行为。 jQuery('#block-block-23 li a').click(function(event) { event.preventDefault(); jQuery(this).addClass("selected"); }); Solved my Prob with jQuery(document ...相关文章
更多- 利用Decommission从Hadoop集群中Remove节点
- Multicast over TCP/IP HOWTO
- ios获取ip地址
- TCP/IP 是如何寻址
- RFC2848--The PINT Service Protocol: Extensions to SIP and SDP for IP Access to Telephone Call Services
- LVS集群:IP负载均衡
- linux下可以限制IP地址对FTP功能的访问吗?
- JavaMail如何获取邮件发送者的IP?
- TCP/IP 相关协议解释
- TCP/IP 发送邮件原理
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。