2012-04-03 32 views
-3

我有一個關於mod_rewrite的一個具體問題:的mod_rewrite/P /約=> P =約

當用戶調用:

www.test.com/p/about

Web服務器應該調用內部

www.test.com/?p=about

訪問網站的子頁面。

但在地址欄中應該還是說

www.test.com/p/about

這是無論如何可能與mod_rewrite的?

我的解決方案,沒有解決:

  1. 嘗試

    RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index.php?p=$1 [L]

Wrong effect, because it only works with: test.com/about, but I need test.com/p/about!

  1. 嘗試

    RewriteRule ^p/([a-zA-Z]+)$ index.php?p=$1

Error: it redirects correct but the paths on the html file are wrong: eg. /img/pic.png is now /p/img/pic.png

非常感謝, 小號三通

+3

你檢查過任何幾乎相同的問題,在右 - 手吧? – jeroen 2012-04-03 22:54:35

+3

是的,它是可能的,實際上它是你可以用'mod_rewrite'完成的最基本的事情之一 - 你有沒有去過它呢?你試過什麼了? – DaveRandom 2012-04-03 22:54:38

+0

或者,正如其他人所說 - 檢查出重複的權利:) – Pete 2012-04-03 22:58:05

回答

2

是的,這是可能的mod_rewrite的:

RewriteRule ^p/([a-zA-Z]+)$ index.php?p=$1 

,或者更一般地說:

RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)$ index.php?$1=$2 

參見:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

+0

對不起,這確實將我重定向到** test.php?p = about **,但adressbar中的地址也變爲** test.php?p = about **,這就是我想要避免的!所以它不像它聽起來那麼簡單! – Stee 2012-04-03 23:39:31

+0

這條規則適用於我 - 你要重定向的PHP腳本是做什麼的? – Pete 2012-04-03 23:42:23

+0

它的一個索引php文件顯示相應的子頁面,在這種情況下,關於頁面。 – Stee 2012-04-04 08:20:22