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

如何使用 mod_rewrite 顯示 SEO 友好的 URL?

How can I display SEO friendly URLs using mod_rewrite?(如何使用 mod_rewrite 顯示 SEO 友好的 URL?)
本文介紹了如何使用 mod_rewrite 顯示 SEO 友好的 URL?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我本質上不是 PHP 開發人員,我被要求在現有的 PHP 網站上執行一些 SEO.

I am not a PHP developer at heart and I have been asked to perform some SEO on an existing PHP website.

我注意到的第一件事是丑陋的 URL,所以我想讓這些 URL 重寫為更具信息性的內容.以下是所有可能的模式:

The first thing I noticed was the ugly URLs so I want to get these to rewrite to something more informative. Here are all the possible patterns:

/index.php?m=ModuleType&categoryID=id
/index.php?m=ModuleType&categoryID=id&productID=id
/index.php?page=PageType
/index.php?page=PageType&detail=yes

所以基本上我想做的是將這些轉換成類似的東西:

So basically what I want to do is convert these into something like:

/ModuleType/Category
/ModuleType/Category/ProductName
/Page
/Page

在任何建議或示例都很棒之前,我還沒有使用過 mod_rewrite!

I haven't used mod_rewrite before any advice or examples would be great!

謝謝.

推薦答案

mod_rewrite 寧愿被用來做相反的事情:在內部將 /ModuleType/Category/ProductName 的請求重寫為 /index.php?m=ModuleType&categoryID=id&productID=id.在文檔中使用新 URL 是您的應用程序的工作.

mod_rewrite would rather be used to do the opposite: rewrite requests of /ModuleType/Category/ProductName internally to /index.php?m=ModuleType&categoryID=id&productID=id. Using the new URLs in the documents is the job of your application.

編輯 下面是一個將參數化網址轉換為新網址的函數示例:

Edit????Here’s an example of how a function might look like that turns your parameterized URLs into the new ones:

function url($url, $rules) {
    $url = parse_url($url);
    parse_str($url['query'], $url['query']);
    $argNames = array_keys($url['query']);
    foreach ($rules as $rule) {
        if ($rule[0] == $url['path'] && array_keys($rule[1]) == $argNames) {
            $newUrl = $rule[2];
            foreach ($rule[1] as $name => $pattern) {
                if (!preg_match('/'.addcslashes($pattern, '/').'/', $url['query'][$name], $match)) {
                    continue 2;
                }
                $newUrl = str_replace('<'.$name.'>', $match[0], $newUrl);
            }
            return $newUrl;
        }
    }
    return $url;
}

$rules = array(
    array(
        '/index.php',
        array('m'=>'.*', 'categoryID'=>'.*', 'productID'=>'.*'),
        '/<m>/<categoryID>/<productID>'
    )
);
echo '<a href="' . url('/index.php?m=ModuleType&categoryID=categoryID&productID=productID', $rules) . '">/ModuleType/Category/ProductName</a>';

這篇關于如何使用 mod_rewrite 顯示 SEO 友好的 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电影手机在线看 | www.欧美 | 国产一区视频在线 | 国产一区三区在线 | 精品一区二区三区不卡 | 日韩精品四区 | 国产一区二区在线免费观看 | 国产第一区二区 | 亚洲一区二区成人 | 亚洲精品一区中文字幕乱码 | 亚洲精品久久久久中文字幕欢迎你 | 精品成人 | 中文字幕国产 | 久久久99精品免费观看 | 丁香久久| 欧美 中文字幕 | 香蕉久久a毛片 | 欧美最猛黑人 | 久久99精品久久久久久 | 国产精品欧美一区二区三区 | 精品国产乱码久久久久久影片 | 久久久综合色 | 亚洲国产一区二区三区 | 国产91久久久久久久免费 | 欧美黄色免费网站 | 草比av | 久久久久久久久久一区二区 | 国产福利在线视频 | 国产精品99一区二区 | 国产亚洲一区二区三区在线观看 | 精品毛片 | 一区二区三区视频在线观看 | 欧美精品久久久 |