PHP目錄裡.htaccess 重新導向到一個檔案

來源:互聯網
上載者:User
請問怎麼配置.htaccess使:
除根目錄下resource檔案夾裡的內容外,其它的路徑都重新導向到根目錄的index.php
如:
http://www.doman.com/resource/.*不重新導向

http://www.doman.com/index.html
http://www.doman.com/config.php
http://www.doman.com/views/index.html
http://www.doman.com/XXX/XX.html
.........
類似以上不是resource裡的內容都重新導向到http://www.doman.com/index.php

謝謝!


回複討論(解決方案)

Redirect 301 ^(^resource)$ http://www.doman.com/index.php

RewriteCond resource/.* !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

Redirect 301 ^(^resource)$ http://www.doman.com/index.php




RewriteCond resource/.* !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]


不好意思,樓上兩位的與我期望的結果不一致哦,
我訪問http://www.doman.com/index.html等並沒有重新導向到http://www.doman.com/index.php哦

不可能!我懷疑你是否寫對了,.htaccess 是否生效了

不可能!我懷疑你是否寫對了,.htaccess 是否生效了


應該生效了,我把.htaccess故意寫錯頁面會出現伺服器錯誤的資訊

不可能!我懷疑你是否寫對了,.htaccess 是否生效了


我在.htaccess裡隨便寫入一些串,會出來 Internal Server Error這個

那就不可能有問題!
我給的規則是經過實際測試的

那就不可能有問題!
我給的規則是經過實際測試的


改成這樣就OK了,會不會跟apache的版本有關?
RewriteEngine On
#RewriteCond resource/.* !-d
RewriteRule ^(?!resource)(.*)$ index.php [QSA,PT,L]

最後簡化成這樣是可行的

RewriteEngine On
RewriteRule ^(?!resource).*$ index.php [PT,L]

最後簡化成這樣是可行的

RewriteEngine On
RewriteRule ^(?!resource).*$ index.php [PT,L]


上面能讓resource.html通過,改成下面的
RewriteEngine On
RewriteRule ^(?!resource /).*$ index.php [PT,L]
  • 聯繫我們

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