[英]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.