简体   繁体   English

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

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

I have a custom MVC app, where in it used IndexController naming convention, which I have built on WAMP. 我有一个自定义的MVC应用程序,其中使用了基于WAMP构建的IndexController命名约定。 Today i tried it to put in to Linux (LAMP).. Strangely, it is giving error "page not found". 今天,我尝试将其放入Linux(LAMP)中。奇怪的是,它给出了错误“找不到页面”。 Can anybody help. 谁能帮忙。 I am not good at mod rewrite, 我不擅长mod重写,

Following is the code 以下是代码

RewriteEngine on

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

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

URL is 网址为

http://hostname/mvc/incident/add

Error is The requested URL /app01/users/public_html/mvc/index.php was not found on this server. 错误是在此服务器上找不到请求的URL /app01/users/public_html/mvc/index.php。

Try either adding: 尝试添加以下任一方法:

RewriteBase /mvc/

just under the RewriteEngine on directive, or add a leading slash to index.php : 就在RewriteEngine on指令下,或在index.php添加一个斜杠:

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

You need to put a / before index.php and some other stuff. 您需要在index.php和其他内容之前放置一个/ Look at the example I got from Wordpress's one. 看一下我从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>

Hi I solved this issue by using error redirecting functionality. 嗨,我通过使用错误重定向功能解决了此问题。 I put following code in my .htaccess file 我将以下代码放入.htaccess文件中

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

and in index.php file i used, $_SERVER['REQUEST_URI'] to get thr URL with query strings 在index.php文件中,我使用了$ _SERVER ['REQUEST_URI']来获取带有查询字符串的网址

I think that ./htaccess configuration is correct. 我认为./htaccess配置正确。 I solved it simply by adding this directive to my apache2.conf file on debian. 我仅通过将此指令添加到我在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