當前位置:首頁 » 編程語言 » phprewriterule

phprewriterule

發布時間: 2022-06-08 23:15:21

php本地如何實現偽靜態頁面

Apache的 mod_rewrite是比較強大的,在進行網站建設時,可以通過這個模塊來實現偽靜態。
主要步驟如下: 1.檢測Apache是否開啟mod_rewrite功能 可以通過php提供的phpinfo()函數查看環境配置,找到「Loaded Moles」,其中列出了所有apache2handler已經開啟的模塊,如果裡麵包括「mod_rewrite」,則已經支持,不再需要繼續設置。如果沒有開啟「mod_rewrite」,則打開目錄 apache目錄下的「/apache/conf/」 ,找到 httpd.conf 文件,再找到「LoadMole rewrite_mole」,將前面的」#」號刪除即表示取用該功能。 如果沒有查找到「LoadMole」 區域,可以在最後一行加入「LoadMole rewrite_mole ,moles/mod_rewrite.so」(獨佔一行),之後重啟apache伺服器。再通過phpinfo()函數查看環境配置就有「mod_rewrite」為項了.。
2.讓apache伺服器支持.htaccess 如何讓自己的本地APACHE伺服器支持:「htaccess」呢? 只需修改apache的httpd.conf設置就可以讓 APACHE支持「.htaccess」了。打開 APACHE目錄的CONF目錄下的httpd.conf文件,找到: Options FollowSymLinks AllowOverride None 改為 Options FollowSymLinks AllowOverride All 就行了。
3.建立.htaccess 文件 建立.htaccess文件時要注意,不能直接建,方法是通過記事本中的另存為菜單,在文件名窗口輸入:「.htaccess」,然後點擊保存。
4.rewrite規則學習 在新建.htaccess文件之後,就在裡面寫入以下內容: RewriteEngine on #rewriteengine為重寫引擎開關on為開啟off為關閉 RewriteRule ([0-9]{1,})$index.php?id=$1 在這里,RewriteRule是重寫規則,是用正則表達式的句子,([0-9]{1,})表示由數字組成的,$表示結束標志,表示以數字結束!如果要實現偽靜態頁面,規則如下: RewriteEngine on RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$index.php?action=$1&id=$2 在為個正則表達式中,([a-zA-Z]{1,})-([0-9]{1,}).html$是規則,index.php?action=$1&id=$2是要替換的格式,$1代表第1括弧匹配的值,$2代表第二個括弧的值,如此類推! 測試PHP腳本如下: index.php文件中的代碼如下: echo 『你的Action值為:』 . $_GET['action']; echo 『 』; echo 『ID值為:』 . $_GET['id']; ?>
在瀏覽器地址欄輸入: localhost/page-18.html 輸出的是: 你的Action值為:page ID值為:18

⑵ PHP 偽靜態 問題 指向錯誤

只要支持偽靜態的,而且從來沒出現過不能訪問的情況,除非下面的代碼寫錯了,我是這樣子做的
RewriteRule taoou/proct-([0-9]+)\.html$ taoou/proct.php?bid=$1
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)\.html$ taoou/proct.php?bname=$1&bid=$2
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct.php?bname=$1&bid=$2&page=$3
RewriteRule taoou/proct2.html$ taoou/proct2.php
RewriteRule taoou/proct2-([0-9]+)\.html$ taoou/proct2.php?bid=$1
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)\.html$ taoou/proct2.php?bname=$1&bid=$2
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct2.php?bname=$1&bid=$2&page=$3
RewriteRule taoou/search.html$ taoou/search.php
RewriteRule taoou/search-([\w]+)\.html$ taoou/search.php?keyword=$1
RewriteRule taoou/search-([\w]+)-([0-9]+)\.html$ taoou/search.php?keyword=$1&page=$2

⑶ PHP編程如何通過Apache開啟URLRewrite(轉)

檢測Apache是否支持mod_rewrite 通過php提供的phpinfo()函數查看環境配置,通過Ctrl+F查找到「Loaded Moles」,其中列出了所有apache2handler已經開啟的模塊,如果裡麵包括「mod_rewrite」,則已經支持,不再需要繼續設置。 如果沒有開啟「mod_rewrite」,則打開目錄 您的apache安裝目錄「/apache/conf/」 下的 httpd.conf 文件,通過Ctrl+F查找到「LoadMole rewrite_mole」,將前面的」#」號刪除即可。 如果沒有查找到,則到「LoadMole」 區域,在最後一行加入「LoadMole rewrite_mole moles/mod_rewrite.so」(必選獨佔一行),然後重啟apache伺服器即可。 讓apache伺服器支持.htaccess AllowOverride None改為Options FollowSymLinks AllowOverride All 就可以了。 建立.htaccess 文件 (1)用記事本打開,點擊文件–另存為,在文件名窗口輸入」.htaccess」,注意是整個綠色部分,也就是包含英文引號,然後點擊保存就行了。 (2)進入cmd命令 窗口,通過cd切換當剛建立htaccess.txt文件的文件夾,然後輸入命令:rename htaccess.txt .htaccess ,然後點擊鍵盤Enter鍵即可。 (3)通過ftp連接htaccess.txt所在文件夾,通過ftp軟體重命名。 rewrite規則學習 我們新建一個.htaccess文件之後,就在裡面寫入以下內容: RewriteEngine on #rewriteengine為重寫引擎開關on為開啟off為關閉 RewriteRule ([0-9]{1,})$ index.php?id=$1 我講解一下RewriteRule:RewriteRule是重寫規則,支持正則表達式的,上面的([0-9]{1,})是指由數字組成的,$是結束標志,說明是以數字結束! 好吧,現在我們可以實現偽靜態頁面了,寫下一下的規則: <IfMole mod_rewrite.c> RewriteEngine on RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2 </IfMole> ([a-zA-Z]{1,})-([0-9]{1,}).html$是規則,index.php?action=$1&id=$2是要替換的格式,$1代表第一個括弧匹配的值,$2代表第二個,如此類推!! 我們寫一個處理的PHP腳本:index.phpPHP代碼<?phpecho 『你的Action是:』 . $_GET['action']; echo 『<br/>』; echo 『你的ID是:』 . $_GET['id'];?>好了,我們現在在瀏覽器中輸入: localhost/view-12.html輸出的是:你的Action是:view

⑷ php怎麼打開重寫 php重寫URL的教程

1. 找到apache的安裝目錄下的conf下的httpd.conf文件,打開文件修改
LoadMole rewrite_mole moles/mod_rewrite.so這行代碼,他前面有個#號,把#號刪掉
2. 還是那個文件,打開,找到
代碼如下 復制代碼
<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>
這個節點,把None改為All. 3. 重啟apache服務
4. 最關鍵的一點,在你得項目目錄下創建.htaccess文件,文件沒有名稱,看上去只是後綴名
具體創建方法不能直接創建,先創建個txt文件(其他的也行),然後另存問,把名字改為.htaccess,並且選所有文件,創建好後,就要制定規則了。 在文件里寫代碼:
RewriteEngine on //on為打開,off為關閉
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
([a-zA-Z]{1,})-([0-9]{1,}).html$是規則,index.php?action=$1&id=$2是要替換的格式,$1代表第一個括弧匹配的值,$2代表第二個,如此類推!

⑸ php偽靜態修改後頁面是空白

這里我配置的,已經可以使用了,你看下是不是用我的方法
RewriteEngine On
RewriteRule taoou/index.html$ taoou/index.php
RewriteRule taoou/gallery.html$ taoou/gallery.php
RewriteRule taoou/why-choose-us.html$ taoou/why-choose-us.php
RewriteRule taoou/how-to-order.html$ taoou/how-to-order.php
RewriteRule taoou/faq.html$ taoou/faq.php
RewriteRule taoou/contact-us.html$ taoou/contact-us.php
RewriteRule taoou/proct.html$ taoou/proct.php
RewriteRule taoou/proct-([0-9]+)\.html$ taoou/proct.php?bid=$1
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)\.html$ taoou/proct.php?bname=$1&bid=$2
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct.php?bname=$1&bid=$2&page=$3
RewriteRule taoou/proct2.html$ taoou/proct2.php
RewriteRule taoou/proct2-([0-9]+)\.html$ taoou/proct2.php?bid=$1
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)\.html$ taoou/proct2.php?bname=$1&bid=$2
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct2.php?bname=$1&bid=$2&page=$3

RewriteRule taoou/search.html$ taoou/search.php
RewriteRule taoou/search-([\w]+)\.html$ taoou/search.php?keyword=$1
RewriteRule taoou/search-([\w]+)-([0-9]+)\.html$ taoou/search.php?keyword=$1&page=$2
RewriteRule taoou/keywords.html$ taoou/keywords.php

RewriteRule taoou/advanced_search.html$ taoou/advanced_search.php

RewriteRule taoou/pinfo-([\w.]+)-([0-9]+)\.html$ taoou/pro-info.php?title=$1&id=$2
RewriteRule taoou/change_currency.html$ taoou/change_currency.php
RewriteRule taoou/shopping-cart.html$ taoou/shopping-cart.php
RewriteRule taoou/cart.html$ taoou/cart.php
RewriteRule taoou/myorder.html$ taoou/myorder.php
RewriteRule taoou/myorder-([0-9]+)\.html$ taoou/myorder.php?page=$1

RewriteRule taoou/a-([\w]+)-([0-9a-z]+)\.html$ taoou/about.php?t=$1&id=$2
RewriteRule taoou/i-([\w]+)-([0-9a-z]+)\.html$ taoou/information.php?t=$1&id=$2
RewriteRule taoou/s-([\w]+)-([0-9a-z]+)\.html$ taoou/service.php?t=$1&id=$2
RewriteRule kaike-info-([0-9]+)\.html$ kaike_info.php?nid=$1

RewriteRule taoou/site-map.html$ taoou/site-map.php

RewriteRule taoou/customer-testimonial.html$ taoou/customer-testimonial.php
RewriteRule taoou/customer-testimonial-([0-9]+)\.html$ taoou/customer-testimonial.php?page=$1

RewriteRule taoou/customer.html$ taoou/customer.php

RewriteRule taoou/links.html$ taoou/links.php
RewriteRule taoou/links-([0-9]+)\.html$ taoou/links.php?page=$1

⑹ 關於PHP urlrewrite的問題

這個可以不用Rewrite實現的。

例如URL為:http://www.abc.com/?XYZ

你要獲取XYZ,應該在index.php文件中這樣寫:

$id=$_SERVER['QUERY_STRING'];
//$id就是獲取到的值

//如果要獲取純整數,請使用下面的代碼
$id=(int)$_SERVER['QUERY_STRING'];

解釋一下:$_SERVER['QUERY_STRING']就是URL中問號(?)後的內容。

這樣就可以了。

熱點內容
怎麼給訂制系統平板安裝安卓系統 發布:2024-05-02 10:29:59 瀏覽:260
雲伺服器做網站伺服器用什麼系統 發布:2024-05-02 10:20:26 瀏覽:896
python經典程序實例 發布:2024-05-02 09:42:07 瀏覽:260
酷豐c10出廠密碼多少 發布:2024-05-02 09:23:33 瀏覽:376
開發安卓游戲需要會什麼 發布:2024-05-02 09:04:22 瀏覽:977
無線網密碼忘了手機怎麼改 發布:2024-05-02 08:57:24 瀏覽:527
iis上傳文件許可權設置 發布:2024-05-02 08:56:39 瀏覽:232
ipad文件加密 發布:2024-05-02 08:20:30 瀏覽:443
粉土壓縮模量 發布:2024-05-02 07:53:59 瀏覽:806
國都證券初始密碼是多少 發布:2024-05-02 07:46:39 瀏覽:110