||  網站導覽  ||  留言版
 
  站長 x 管理人
 
  文章分類
    JAVA
    Database資料庫
    應用程式
    文書處理
    normal一般設定
    Web-design網頁設計
    Virtual Machine虛擬機器
    MIS網管
       Mac
       不分類
       Windows
       Linux
    media多媒體
    未分類
 
 
 
 
apache_mod_rewrite將特定目錄和port重導向
 
 
 
 
同事的客戶要求網站要Listen 80和8080
port 80是給前台使用者,例:http://abc.com/index.php
port 8080給後台管理者用,例:http://abc.com:8080/admin/index.php

重點是port 80禁止進入後台
並且不希望用兩個VirtualHost的方式
(其實兩個VirtualHost DocumentRoot也是可以一樣的啊…)

以下為httpd.conf實作結果:
一、檢查mod_rewrite是否載入
LoadModule rewrite_module modules/mod_rewrite.so

二、增加Listen的port
在原本的Listen 80後面再加一個
Listen 8080

三、修改<Directory "/var/www/html">
<Directory "/var/www/html">
略…
 
RewriteEngine on
 
#it's like DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*) http://%{SERVER_NAME}:%{SERVER_PORT}%{REQUEST_URI}index.php [L]
 
 
#80 port /admin to no_priv.php 
RewriteCond  %{SERVER_PORT} ^80$
RewriteCond  %{REQUEST_URI} ^/admin/*
 
RewriteRule ^(.*) http://%{SERVER_NAME}/no_priv.php
</Directory>

大致完成需求了

 
 
 
 
Copyright © 2012 NBOX. All Rights Reserved.