1. 程式人生 > >Apache PHP開啟偽靜態

Apache PHP開啟偽靜態

開啟apache的配置檔案httpd.conf

第一步:找到

#LoadModule rewrite_module modules/mod_rewrite.so

把前面#去掉。沒有則新增,但必選獨佔一行,使apache支援 mod_rewrite 模組

第二步:找到

<Directory "F:/Apache_Workspace/PHP">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks


    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None


    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all


</Directory>


把AllowOverride None 換成 AllowOverride All 使apache支援 .htaccess 檔案

第三步:重啟apache伺服器


在要啟用偽靜態的 PHP 專案根目錄下建立 .htaccess 檔案





在 .htaccess 檔案中輸入內容

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule index.html$ index.php
    RewriteRule index-([1-9]+[0-9]*).html$ index.php?p=$1
    RewriteRule ([a-z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
</IfModule>
註釋:


RewriteEngine   為重寫引擎開關,on為開啟,off為關閉。

RewriteRule     是路由轉向規則,$ 之前路徑為瀏覽器中要輸入路徑,這裡可以用正則表示式表達。$+空格 後路徑為後臺實際轉向路徑,轉向後臺實際路徑時可以傳引數,例子裡的後臺頁面可以用$_GET['p']   $_GET['action']  $_GET['id'] 來接收

$1 代表瀏覽器路徑中輸入的第一個正則表示式的值,以此類推

$2代表第二個正則表示式的值

RewriteRule 路由轉向規則里正則表示式用括號 () 括起來

第四步:在專案(test)下 index.php 頁面內寫入內容


<?php
if ($_GET ['p']) {
    echo "p : " . $_GET ['p'];
}

if ($_GET ['action']) {
    echo "action : " . $_GET ['action'];
}

if ($_GET ['id']) {
    echo "id : " . $_GET ['id'];
}
?>

在瀏覽器中輸入

http://localhost/test/index.html
http://localhost/test/index-99.html
http://localhost/test/page-18.html

都會轉向 http://localhost/test/index.php 頁面並且依次

http://localhost/test/index.html     頁面什麼都不顯示


http://localhost/test/index-99.html  頁面顯示 p : 99


http://localhost/test/page-18.html   頁面顯示 action : pageid : 18


相關推薦

Apache PHP開啟靜態

開啟apache的配置檔案httpd.conf 第一步:找到 #LoadModule rewrite_module modules/mod_rewrite.so 把前面#去掉。沒有則新增,但必選獨

PHP開啟靜態(AppServ伺服器)

mod_rewrite是Apache的一個非常強大的功能,它可以實現偽靜態頁面。下面我詳細說說它的使用方法 1.檢測Apache

PHP配置環境中如何開啟靜態

技術分享 重要 ont clas word wid 知識 .net pla 1、在httpd.conf中引入httpd-vhosts.conf 2、在httpd.conf中開啟mod_rewrite.so 3、在httpd-vhosts.conf中配置虛擬主機

centos7 apache開啟靜態

編輯Apache配置檔案 nano /etc/httpd/conf/httpd.conf 找到以下內容, Include conf.modules.d/*.conf 在上面一行之後新增以下內容, LoadModule rewrite_module modules/m

Apache開啟靜態示例

Apache開啟偽靜態示例 環境:系統 Windows Apache 2.2 載入Rewrite模組: 在conf目錄下httpd.conf中找到 LoadModule rewrite_module modules/mod_rewrite.so 這句,去掉前邊的註釋符號“

php簡單靜態實例

需要 rewrite 鍵盤 ctrl+ acc tor iter hand $1 mod_rewrite是Apache的一個非常強大的功能,它可以實現偽靜態頁面。下面我詳細說說它的使用方法!對初學者很有用的哦!1.檢測Apache是否支持mod_rewrite通過php提供

CentOS7 下配置Apache支援.htaccess靜態檔案

在安裝好apache、mysql、php之後,在訪問系統的一些頁面時總是報404,檢視日誌報錯[client xxx:45783] script '/var/www/html/xxx/about.php' not found or unable to stat,搜尋資料後發現是需要手工啟

linux讓Apache支援.htaccess靜態檔案時遇到的坑

相信很多人都在windows環境開發好專案後再佈置到linux上,但這個時候或許你發現你的偽靜態不起作用了,很無奈,或許你還沒進行相關配置。 這個時候你就得做一下幾步操作了。。。。。 第一、編輯httpd.conf檔案 ----------------- 1、 - 在etc/httpd/

wdcp面板下wordpress開啟靜態404解決方法

建站面板由於換成了WDCP然後worpress設定偽靜態的時候,突然發現首頁能訪問,文章頁開啟404,經過各種查閱資料,整理了下解決方法; 1.手寫在後臺【Rewrite規則管理】新增規則wordpress.conf(這裡隨意命名,為了方便,我命名為WordPress)

thinkphp3.2.3之apache轉nginx靜態設定

本地開發的專案,使用的是apache伺服器,完成專案之後,之前搭建到的伺服器都是Windows伺服器上,從而上線,這次需要在寶塔上nginx伺服器上搭建,所以需要將apache的偽靜態更改為nginx:1.在網上搜索到的基本上都不是自己理想狀態下的需求,搜尋到的方法基本上與比

centos下Apache伺服器ThinkPHP靜態的設定方法

windows下的apache配置在linux下有所不同,linux下檢視phpinfo下能找到mod_rewrite模組則表示載入了重寫模組,不必管配置檔案是否有有載入. 確認載入了模組後需

Apache環境.htaccess靜態301跳轉(www與不帶www)

之前老左分享過一篇"LNMP系列教程之五:設定301重定向的方法"一文,我們可以很容易的在nginx環境下設定301跳轉。一般而言,我們使用的301跳轉就是WWW與不帶WWW域名之間的跳轉,用行話說就是權重要歸一。對於我們使用Apache環境的來說其實相對nginx比較簡

URL優化之IIS7如何開啟靜態

iis7跟IIS6開啟偽靜態重寫的方式不一樣,iis6是在網站屬性裡面的ISAPI篩選器裡面新增,但是iis7新增偽靜態重寫,需要下載一個url重寫外掛。 II7/7.5用的是web.config配置檔案,這個配置檔案可以配置偽靜態、301等等功能。 web.conf

centos 開啟apache靜態

apache1.開啟rewrite模塊vim httpd.conf #[plain] view plain copy LoadModule rewrite_module modules/mod_rewrite.so2.開啟AllowOverride[plain] view plain copy # # A

PHP通過apache的mod_rewrite實現靜態

1、首先開啟apache裡的mod_rewrite模組  去掉 LoadModule rewrite_module modules/mod_rewrite.so 這一行前面的 “#” 2、在專案的根目錄下新建.htaccess檔案,用notepad++ 或者其它編輯器開

PHP專案部署-開啟rewrite(靜態

TIPS:作者所用環境為2.4.25(Unix),不同版本配置應該會有所差異。 1、httpd.conf配置。 #LoadModule rewrite_module modules/mod_rewrite.so 去掉# TIPS:開啟mod_rewr

Apache開啟虛擬機器配置及靜態規則

學習記錄,配置Apache2.4版本支援虛擬機器並啟用偽靜態規則。1、修改配置檔案先編輯Apache的conf目錄下的httpd.conf檔案。去除# LoadModule rewrite_module modules/mod_rewrite.so的註釋,開啟mod_rewr

phpapache rewrite靜態的簡單配置和使用

      1、為什麼要使用偽靜態: 真正的靜態頁面空間儲存量大,進行刪除或者更新這些html檔案時可造成大量檔案碎片,破壞磁碟壞道, 動態頁面雖然可以實時更新,但是有時會導致死迴圈,對搜尋引擎不友好,而偽靜態卻不會出現這種情況。 偽靜態可以更好的緩解伺服器的壓力,增強搜尋

Ubuntu 12.04 搭建PHP環境(MySQL+PHP+Apache環境)手把手教程 含靜態

http://blog.sina.com.cn/s/blog_3f6b8ac001015arb.html 2.切換管理員身份 sudo su 3.開始安裝mysql5 apt-get install mysql-server mysql-client 要求輸入r

如何在windows下apache環境開啟htaccess靜態功能

.htaccess是一種非常強大的配置檔案一般情況下用於虛擬主機可是由於WordPress等開源程式自動生成.htaccess,所以導致一些使用VPS的站長無法正常使用下面介紹讓Windows環境下的Apache支援.htaccess偽靜態的方法修改Apache1、開啟Ap