2010-05-25 55 views
0

我使用Apache 2.2和mod_rewrite。我想採取以下網址並將它們映射到另一個網址。該模式是簡單和這樣的:modrewrite RewriteRule問題

http://domain/test/ex1.html - >http://domain/app/index.php/content/?name=ex1

我試圖在一個.htaccess中(發生在/測試/目錄中的文檔根):

RewriteEngine On 
RewriteBase /app/ 
RewriteRule (.*)\.html index.php/content/?name=$1 

RewriteEngine On 
RewriteRule (.*)\.html /app/index.php/content/?name=$1 

我不確定反向引用是否正確,因此設置爲$ 0和$ 2,但似乎沒有幫助。

我也試過RewriteLogLevel設定到9

有一個步驟,其中它幾乎有: 重寫 'ex1.html' - > '?的index.php /內容/名稱= EX1'

重寫日誌的最後一行如下: [perdir /無功/網絡/域/ htdocs中/測試/]內部重定向與/app/index.php/content/ [INTERNAL REDIRECT]

如何能我得到這個重寫爲/app/index.php/content/?name=ex1?

編輯 因此使用此作爲文檔根目錄文件的.htacces爲RedirectMatch工作:

RewriteEngine On 
RewriteBase/
RedirectMatch ^(.*)/(.*)\.html$ http://domain/app/index.php/content/?name=$2 
#this doesnt work - adding to docroot allows for it to pick up but still using test/ex1 rather than just ex1 
#RewriteRule ^(.*)\.html$ /app/index.php/content/?name=$1 

任何越來越底部重寫規則(當前註釋掉)工作的幫助將不勝感激。

感謝

回答

1

在你提到的結構域/測試你的例子/所以我基於/test/*.html重寫爲/app/index.php/content/?name=

RewriteEngine On 
RewriteBase/
RewriteRule ^test/(.*)\.html$ /app/index.php/content/?name=$1 

Tha噸應該工作。

+0

嗯....重讀我原來的文章,因爲這似乎並沒有工作。我假設這將是一個位於docroot的.htaccess文件?由於某種原因,它仍然無法正常工作。呃.. – timpone 2010-05-25 22:31:23

+0

反向引用它通過目錄的測試,所以test/ex1而不是僅僅插入$ 1的ex1。 thx任何幫助 – timpone 2010-05-26 01:46:27

0

嗯,把我的頭頂部:

RewriteCond %{REQUEST_URI} ^/app/(.*)\.html$ 
RewriteRule ^/app/(.*)\.html$ /app/index.php/content/?name=$1 

這假定重寫基地/

+0

看起來像應用程序 - >測試基於以上dir結構? – timpone 2010-05-25 22:42:30

+0

我不確定我是否理解你的評論。如果原始URI是/test/foo.html,並且目標是/app/index.php/content/?name=foo,那麼請查看我編輯的答案... – ivans 2010-05-25 22:50:59

+0

我很確定/ content /在重寫導致mod_rewrite有問題,因爲它考慮到在這種情況下的路徑(測試) – timpone 2010-05-25 23:20:15