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

在 URL 中傳遞多個值時,PHP 中的 URL 重寫

URL rewriting in PHP when several values are being passed in the URL(在 URL 中傳遞多個值時,PHP 中的 URL 重寫)
本文介紹了在 URL 中傳遞多個值時,PHP 中的 URL 重寫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在研究如何使用 Mod rewrite 修改 php 中的 URL.

I am currently researching how to modify URLs in php using Mod rewrite.

典型的 URL 可能如下所示:

A typical URL could look like this:

http://www.fitness.com/find_a_pt/?county=&constituency=211&gender=&action=search

現在在上面的例子中只選擇了一個選區.未指定縣或性別.

Now in the above example only a constituency has been selected. No county or gender has been specified.

現在上述選區指的是達特福德".

Now the above constituency refers to 'Dartford'.

所以如果 URL 是這樣就好了:

So it would be good if the URL read:

http://www.fitness.com/find_a_pt/dartford

現在增加的復雜性是性別可能是:

Now the added complication is that a gender may be either:

1) 未選擇 - 根據上面的網址

1) Not selected - as per the URL above

2) 男

http://www.ego3fitness.com/find_a_pt/?county=&constituency=211&gender=1&action=search

3) 女性

http://www.ego3fitness.com/find_a_pt/?county=&constituency=211&gender=&actiom=search

因此 URL 需要讀取:

So the URLs would need to read:

1) http://www.fitness.com/find_a_pt/dartford

2) http://www.fitness.com/find_a_pt/dartford/male

3) http://www.fitness.com/find_a_pt/dartford/female

首先,URL 重寫是否可以做到這一點,如果可以,有人可以提供一個示例供我使用.

Firstly is it possible to be this specific with the URL rewrites and if so could someone provide an example for me to work from.

提前感謝您的幫助.

推薦答案

我總是使用相同的 mode_rewrite 規則:

I always use the same mode_rewrite rules:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

有了這個規則,一切都被轉發到 index.php.所以你可以自由地用 PHP 實現每一個 url 邏輯.

With this rules everything is forwared to index.php. So you are free to implement every url logic with PHP.

您可以使用 $_SERVER['REQUEST_URI'] 獲取請求 uri,然后做任何您想做的事情.

You can get the request uri with $_SERVER['REQUEST_URI'] and do whatever you want.

很高興有一個帶有正則表達式規則的路由類來解析 uri.看一個例子 here 并閱讀Zend、Code Igniter 等大型框架是如何做到的.(順便說一下,我提供的重寫規則來自Zend Framework)

It is nice to have a Routing class with regex rules to parse the uri. Look at an example here and also read how the big frameworks like Zend, Code Igniter etc. do it. (The rewrite rule I provided is from Zend Framework by the way)

這篇關于在 URL 中傳遞多個值時,PHP 中的 URL 重寫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 示例)
主站蜘蛛池模板: 亚洲国产精品久久久久久 | 美女久久| 精品一区二区不卡 | 日韩一区二区三区在线观看 | 一区二区免费在线观看 | 国产欧美在线 | 蜜桃一区 | 九九热在线精品视频 | 国产精品久久久久久吹潮 | 国产精品久久久久久妇女 | 特黄特色大片免费视频观看 | av网站免费| 欧美在线观看免费观看视频 | 男女羞羞免费网站 | 日韩在线视频一区二区三区 | 国产一区二区三区四区五区3d | 中文精品一区二区 | 波多野结衣精品 | 在线观看视频中文字幕 | 久久一级 | 色久影院 | 久久九九99| 免费视频一区二区 | 国产97人人超碰caoprom | 一区二区三区视频在线免费观看 | 欧美福利 | 99在线免费观看视频 | 成人小视频在线观看 | 欧美精品一区三区 | 国产一区二区三区视频 | 亚洲综合二区 | 国产精品嫩草影院精东 | 日韩综合 | 天天摸天天看 | 久久精品青青大伊人av | av高清毛片 | 日韩中文字幕在线播放 | 在线一区视频 | 99精品免费视频 | 国产高潮好爽受不了了夜色 | 天天在线操 |