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

PHP .htaccess ->漂亮的網址(反向)

PHP .htaccess -gt; pretty url (in reverse)(PHP .htaccess -漂亮的網址(反向))
本文介紹了PHP .htaccess ->漂亮的網址(反向)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我知道如何重寫 URL,例如:www.example.com/index.php?id=1&cat=3www.example.com/1/3/(或其他).我知道.

I know how to make URL's rewrite, for example: www.example.com/index.php?id=1&cat=3 to www.example.com/1/3/ (or whatever). I know that.

我不知道到底如何將所有頁面中的整個鏈接更改為鏈接到漂亮的 URL.我網站的所有鏈接都是老式的(<a href="index.php?id=1&cat=2">),而且有很多.

What I don't know is how on earth to change my whole links in all pages to link to pretty URL's. All my site's links are old fashion (<a href="index.php?id=1&cat=2">) and there are many.

我問如果用戶點擊 index.php?id=1,是否有人有想法或知道如何自動重定向到那個漂亮的 url.(如果您更改網址中的標題,則幾乎就像這個站點 Stackoverflow).

I`m asking if someone has an idea or know how to automaticaly redirect to that pretty url if the user click on index.php?id=1. (Almost like this site Stackoverflow if you change title in the url).

所以我的假設是...

  1. 用.htaccess讀取index.php?id=1&cat=2重寫index/1/3,自己又解釋了(奇怪)

  1. Use .htaccess to read the index.php?id=1&cat=2 to rewrite index/1/3 that itself interprets again (strange)

一個用于執行 htaccess 重寫回原始重定向的 php 文件...

a php file to do the redirects that htaccess rewrites back to original...

結論:將<a href="index.php?id=1&....">自動更改為index/1/2

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

##################################
# This turns index.php?id=1&cat=2 into index/1/2 and then back 'transparent' into    index.php?id=1&cat=2 if you have old fashioned
# links in your site and don't want to change them :)


# Avoid mod_rewrite infinite loops 
# This is critical if you want to use this code

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

# Hard-rewrite ("[R]") to "friendly" URL.
# Needs RewriteCond to match original querystring.
# Uses "?" in target to remove original querystring,
#   and "%n" backrefs to move its components.
# Target must be a full path as it's a hard-rewrite.
RewriteCond %{QUERY_STRING} ^id=(d+)&cat=(d+)$
RewriteRule ^index.php$ http://localhost/index/%1/%2/? [L,R]

# Soft-rewrite from "friendly" URL to "real" URL.
# Transparent to browser.
# Won't re-trigger the above rewrite, though I'm
#   not really sure why! The order of the rules
#   doesn't seem to make a difference.
RewriteRule ^index/(d+)/(d+)/$ index.php?id=$1&cat=$2 [L]

推薦答案

RewriteEngine on

# Prevents browser looping, which does seem
#   to occur in some specific scenarios. Can't
#   explain the mechanics of this problem in
#   detail, but there we go.
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

# Hard-rewrite ("[R]") to "friendly" URL.
# Needs RewriteCond to match original querystring.
# Uses "?" in target to remove original querystring,
#   and "%n" backrefs to move its components.
# Target must be a full path as it's a hard-rewrite.
RewriteCond %{QUERY_STRING} ^id=(d+)&cat=(d+)$
RewriteRule ^index.php$ http://example.com/index/%1/%2/? [L,R]

# Soft-rewrite from "friendly" URL to "real" URL.
# Transparent to browser.
RewriteRule ^index/(d+)/(d+)/$ /index.php?id=$1&cat=$2

當然,理想情況下,您只需修復鏈接,然后只需要軟重寫即可.:)

Of course, ideally, you'd just fix your links, and then you'd only require the soft-rewrite. :)

使用 Apache/2.2.3 測試.我想我編造了硬重寫"和軟重寫"這兩個術語.

這篇關于PHP .htaccess ->漂亮的網址(反向)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 示例)
主站蜘蛛池模板: 大学生a级毛片免费视频 | 国产1区在线 | 欧美色999| 中文字幕在线一区 | 99精品欧美一区二区三区 | 精品国产18久久久久久二百 | 欧美一区二区成人 | 午夜视频一区二区 | 91亚洲精选| 91视频电影 | 亚洲精品视频免费观看 | 91亚洲国产成人久久精品网站 | 日本精品一区二区三区在线观看视频 | 黄色网址在线免费观看 | 一区二区三区四区视频 | www.操com| 成人国产精品久久 | 久久精品二区 | av免费观看在线 | 夜久久| 伊人春色在线 | 国产精品毛片无码 | 欧美精品在线观看 | 日韩一区和二区 | 久久久久一区二区三区 | 亚洲免费精品 | 欧美精品在线一区 | 新超碰97 | 亚洲国产成人精品久久久国产成人一区 | 久久国内| 欧美日韩18| 久久一区二区视频 | 久久三区 | 岛国精品 | a级免费黄色片 | 色网站入口 | 春色av| 97中文视频 | www.中文字幕.com| 成人国产精品久久 | 三级av在线 |