關於apache伺服器rewrite

來源:互聯網
上載者:User
我的目的是在地址欄輸入的url:
http://localhost/project/ShortURL/index.php/149Ui3
自動重寫為
http://localhost/project/ShortURL/index.php?controller=jump&method=jemp&code=149Ui3
apache中添加配置如下(apache2.conf):
     # Turn on rewrite engine     Options +FollowSymlinks     RewriteEngine on     # More rules below     RewriteRule ^index.php/(.*)$ index.php?controller=jump&method=jump&code=$1 [QSA]

但是始終不能跳轉,請問應該如何正確配置呢.


回複討論(解決方案)

1.httpd.conf中rewrite模組是否正確開啟
2.你寫入的這個設定檔是否有效

我在ubuntu下,沒有發現httpd.conf檔案,主設定檔只有apach2.conf,另外現在的配置是這樣的.
1.在/var/www/project/ShortURL目錄下建立一個.htaccss檔案內容如下:

# Turn on rewrite engineOptions +FollowSymlinksRewriteEngine on# More rules belowRewriteRule ^index.php/(.*)$ index.php?controller=jump&method=jump&code=$1 [QSA

2.在apach2.conf中做了如下配置:
    Options FollowSymLinks    AllowOverride ALL    Require all granted

別的沒有做配置.現在的問題是這樣的:
現在問題是每次輸入http://localhost/project/ShortURL/index.php/149Ui3都會顯示沒有css樣式控制的http://localhost/project/ShortURL/index.php內容(地址欄還是http://localhost/project/ShortURL/index.php/149Ui3),不能跳轉到http://localhost/project/ShortURL/index.php?controller=jump&method=jemp&code=149Ui3這個地址

1.httpd.conf中rewrite模組是否正確開啟
2.你寫入的這個設定檔是否有效


現在的如#2樓所示,不好意思回複錯了.

問題解決了,總結一下:
問題描述:
我的目的是在地址欄輸入的url:
http://localhost/project/ShortURL/index.php/149Ui3
自動重寫為
http://localhost/project/ShortURL/index.php?controller=jump&method=jump&code=149Ui3
解決方案
1.在apach2.conf中做如下配置:

Options FollowSymLinks
AllowOverride ALL
Require all granted

2.在/var/www/project/ShortURL目錄下建立一個.htaccss檔案內容如下:
# Turn on rewrite engine
RewriteEngine on
# More rules below
RewriteBase /
RewriteRule ^index.php/(.*)$ http://localhost/project/ShortURL/index.php?controller=jump&method=j ump&code=$1 [L,R=301]
寫在最後
沒事的時候還得多看文檔啊,感謝開源中國瘋狂的蝸牛提供的思路.

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.