linux Ubuntu apache2 偽靜態設定

來源:互聯網
上載者:User

標籤:

Ubuntu Apache 偽靜態配置 url重寫 步驟:
1.載入rewrite模組
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

2.將您的主機的<Directory></Directory>中的AllowOverride None改為AllowOverride All (我這邊是/etc/apache2/apache2.conf)

3.在你的網站的目錄下建立.htaccess檔案
並建立如下內容
RewriteEngine on

(在這個地方如果報

[Sat Jan 24 07:51:53.568313 2015] [core:alert] [pid 1043] [client 101.130.216.102:51423] /var/www/html/.htaccess: Invalid command ‘ewriteEngine‘, perhaps misspelled or defined by a module not included in the server configuration錯誤,很可能是因為拼字錯誤,我在第一次配置的時候把RewriteEngine on寫成了ewriteEngine on

報錯的話可以 vim /var/log/apache2/error.log

查看)
RewriteBase   /
RewriteRule ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3

其中RewriteRule是例子,意思為在瀏覽器中輸入的是show-1-2.html,而實際訪問的卻是show.php?itemid=1&page=2


4.重啟apache2

5.測試

在show.php 輸入

<?php 
echo $_GET[‘itemid‘].$_GET[‘page‘];
?>

linux Ubuntu apache2 偽靜態設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.