簡體   English   中英

Apache Rewrite URL,可以在WAMP中使用,而不能在LAMP中使用

[英]Apache Rewrite URL, Works in WAMP, not in LAMP

我有一個自定義的MVC應用程序,其中使用了基於WAMP構建的IndexController命名約定。 今天,我嘗試將其放入Linux(LAMP)中。奇怪的是,它給出了錯誤“找不到頁面”。 誰能幫忙。 我不擅長mod重寫,

以下是代碼

RewriteEngine on

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

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

網址為

http://hostname/mvc/incident/add

錯誤是在此服務器上找不到請求的URL /app01/users/public_html/mvc/index.php。

嘗試添加以下任一方法:

RewriteBase /mvc/

就在RewriteEngine on指令下,或在index.php添加一個斜杠:

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

您需要在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>

嗨,我通過使用錯誤重定向功能解決了此問題。 我將以下代碼放入.htaccess文件中

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

在index.php文件中,我使用了$ _SERVER ['REQUEST_URI']來獲取帶有查詢字符串的網址

我認為./htaccess配置正確。 我僅通過將此指令添加到我在debian上的apache2.conf文件中即可解決此問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM