久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 .htaccess 重寫 Mod

Mod rewrite using .htaccess(使用 .htaccess 重寫 Mod)
本文介紹了使用 .htaccess 重寫 Mod的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用此信息[從網站復制]重寫我的模式,但它不起作用..有什么問題,請給出正確答案..

I am trying to Rewrite my mode using this info[copy from a website], but it's not working .. what's wrong with it and plz give a correct answer..

Apache重寫引擎主要用于將www.yoursite.com/product.php?id=123等動態url轉為www.yoursite.com/product/123等靜態且用戶友好的url

The Apache rewrite engine is mainly used to turn dynamic url’s such as www.yoursite.com/product.php?id=123 into static and user friendly url’s such as www.yoursite.com/product/123

RewriteEngine on
RewriteRule ^product/([^/.]+)/?$ product.php?id=$1 [L]

另一個例子,重寫自:

www.yoursite.com/script.php?product=123 到 www.yoursite.com/cat/product/123/

www.yoursite.com/script.php?product=123 to www.yoursite.com/cat/product/123/

RewriteRule cat/(.*)/(.*)/$ /script.php?$1=$2

推薦答案

您似乎誤解了重寫模塊(尤其是您的規則)的實際作用.

You seem to have misunderstood what the rewrite module (and your rules specifically) actually does.

很簡單,當您瀏覽到:

 localhost/abc/product.php?id=23

RewriteRule 沒有被調用,也不應該做任何事情.這里沒有任何問題,您只是瀏覽了錯誤 URL

The RewriteRule isn't invoked and shouldn't be doing anything. There's nothing wrong here, you're just browsing to the wrong URL

http://www.yoursite.com/product/123         <- URL that user goes to
http://www.yoursite.com/product.php?id=123  <- Rewritten URL that the server sees

解釋了重寫規則

重寫規則分為三個部分(不包括RewriteRule部分...)

RewriteRule(s) explanined

A rewrite rule is broken down into three parts (not including the RewriteRule part...)

  1. 它與 url 匹配的正則表達式
  2. 它轉換成的網址
  3. 其他選項

根據您的規則:

RewriteRule ^product/([^/.]+)/?$ product.php?id=$1 [L]

正則表達式為:^product/([^/.]+)/?$
新網址:product.php?id=$1
選項:[L]

這意味著用戶瀏覽到 nice url http://www.yoursite.com/product/123(并且您的所有鏈接都指向 nice URL),然后服務器與正則表達式匹配并將其轉換為只有服務器可以看到的新 URL.

This means that the user browses to the nice url http://www.yoursite.com/product/123 (and all of your links point to the nice URLs) and then the server matches against the regex and transforms it to the new URL that only the server sees.

實際上,這意味著您有兩個 URL 指向同一頁面...nice URL 和 not-nice URL 都將帶您到同一個地方.不同之處在于,不太好/標準 URL 對普通公眾和其他訪問您網站的人是隱藏的.

Effectively, this means that you have two URLs pointing to the same page... The nice URL and the not-nice URL both of which will take you to the same place. The difference is that the not-nice / standard URL is hidden from the general public and others pursuing your site.

http://mysite.com/product/image.jpg 沒有被重定向的原因是因為您在 RewriteRule 中使用了正則表達式.

The reason why http://mysite.com/product/image.jpg is not being redirected is because of the regex that you use in your RewriteRule.

^product/([^/.]+)/?$

  • ^ => 字符串開始
  • product/ => 匹配文字字符串 product/
  • ([^/.]+) => 匹配一個或多個字符直到下一個/的捕獲組>.
  • /?$ => 匹配可選的 / 后跟字符串的結尾
    • ^ => Start of string
    • product/ => Matches the literal string product/
    • ([^/.]+) => A capture group matching one or more characters up until the next / or .
    • /?$ => Matches an optional / followed by the end of the string
    • 給定網址:

      http://mysite.com/product/image.jpg
      

      您的正則表達式匹配 product/image 但隨后遇到 . 這會停止匹配...因為那不是字符串 $ 規則無效,因此轉換永遠不會發生.

      Your regex matches product/image but then it encounters . which stops the matching... As that isn't the end of string $ the rule is invalidated and thus the transform never happens.

      您可以通過將字符類 [^/.] 更改為 [^/] 或 - 我的 首選 方法 -刪除字符類并簡單地使用 .+ (看到您無論如何都將所有內容捕獲到字符串的末尾

      You can fix this by changing your character class [^/.] to just [^/] or - my preferred method - to remove the character class and simply use .+ (seeing as your capturing everything to the end of the string anyway

      RewriteRule ^product/([^/]+)/?$ product.php?id=$1 [L]
      RewriteRule ^product/(.+)/?$ product.php?id=$1 [L]
      

      這篇關于使用 .htaccess 重寫 Mod的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 国产超碰人人爽人人做人人爱 | 97av在线| 日韩一区二区在线播放 | 精品videossex高潮汇编 | 日韩中文在线视频 | 精品免费视频一区二区 | 欧美成年人视频在线观看 | 免费毛片网站 | 欧美在线色视频 | 亚洲精品国产区 | 美国一级片在线观看 | 午夜伦理影院 | 日本一区二区三区在线观看 | 久久久国产一区二区三区 | 99欧美精品| 国产精品一区二区久久 | 精品一区二区观看 | 色综合久久天天综合网 | 日韩高清一区二区 | 日韩a| 欧美国产精品一区二区 | 伊人精品在线视频 | 国产精品欧美日韩 | 成人在线中文字幕 | 国产精品99久久久久久人 | 免费的日批视频 | 中文字幕av在线一二三区 | 久草精品视频 | 欧美午夜一区 | 精品免费国产一区二区三区四区 | 国精产品一区二区三区 | 成人免费一区二区三区牛牛 | 亚洲国产精品激情在线观看 | 国产美女精品视频免费观看 | 亚洲欧美精品 | 黄色三级免费 | 国产剧情一区 | 欧美一级全黄 | 亚洲成人天堂 | 懂色一区二区三区免费观看 | 国产日韩免费视频 |