2012-09-19 30 views
0

我有一個自定義的MVC應用程序,其中使用了IndexController命名約定,這是我在WAMP上構建的。今天我試着把它放到Linux(LAMP)中。奇怪的是,它給出錯誤「頁面未找到」。任何人都可以幫忙嗎?我在國防部重寫不好,Apache重寫URL,在WAMP中工作,不在LAMP中

以下是代碼

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ index.php?request=$1 [L,QSA] 

網址是

http://hostname/mvc/incident/add

錯誤是請求的網址/ app01 /用戶/的public_html /在此服務器上找不到mvc/index.php。

+0

我檢查httpd.conf中,發現了mod_rewrite啓用 的LoadModule rewrite_module模塊/ mod_rewrite.so – Codemator

回答

0

嗨我通過使用錯誤重定向功能解決了這個問題。我把下面的代碼在我的.htaccess文件

ErrorDocument 403 /~renjith/mvc/index.php 
ErrorDocument 404 /~renjith/mvc/index.php 

和index.php文件我用,$ _ SERVER [「REQUEST_URI」]來獲得與查詢字符串URL THR

0

嘗試要麼加入:

RewriteBase /mvc/ 

剛下RewriteEngine on指令,或添加斜線到index.php

RewriteRule ^(.*)$ /mvc/index.php?request=$1 [L,QSA] 
+0

現在的錯誤是請求的網址的index.php在此服務器上未找到。 – Codemator

+0

@Renjith所以哪裏*是*'index.php'?你的htaccess文件在哪裏? –

+0

裏面mvc文件夾 有2個文件夾和2個文件。 文件夾是「應用程序」和「公共」。 文件是.htaccess和index.php – Codemator

0

你需要把index.php/和一些其他的東西。看看我從Wordpress獲得的例子。

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
+0

不幸的是,當我在index.php前加上斜槓時會出現新的錯誤 在此服務器上未找到請求的URL /index.php。 – Codemator

+0

你是否完全複製了上述內容?如果它位於域的根目錄的子目錄中,則需要更改「RewriteBase」以匹配它。 – FluffyJack

+0

是的,我確實做到了 – Codemator

0

我認爲./htaccess配置是正確的。我簡單地通過將此指令添加到debian上的我的apache2.conf文件來解決它。

<Directory /var/www/html/your_app_folder> 
Options Indexes FollowSymLinks 
AllowOverride All 
Require all granted</Directory> 
+0

比a2enmod重寫&服務apache2重新啓動。這可能需要一些時間才能工作,因爲瀏覽器可能有一些舊的緩存。要檢查它是否值得嘗試另一個。 –