删除文件扩展名时出现404错误,但在wamp上不起作用 [英] getting 404 error when removing file extension worked on wamp but not working on lamp

查看:76
本文介绍了删除文件扩展名时出现404错误,但在wamp上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在admin文件夹中的htacesss文件中,删除了wamp上的php扩展名,尽管效果很好。与灯泡服务器一起移至ubuntu时。却找不到404。但是htaccess可以完美地用于其他诸如索引路由之类的东西。下面是我在htaccess文件上使用的内容。

in htacesss file in admin folder, removed php extension on wamp although worked fine. when moved to ubuntu with lamp server. it's giving 404 not found. but htaccess working perfectly for other thing like index routing.Below what i am using on htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
DirectoryIndex index.php


推荐答案

尝试以下规则:-

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

OR

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

OR

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

如果此全局规则不适合您,然后尝试以下代码:-

If this global rules is not working for you then try below code also:-

在此代码中,将'work'替换为您的项目根目录。

In this code replace 'work' with your project root directory.

RewriteEngine on
RewriteBase /work/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule .* $0.php [L]

在Linux中,您需要打开重写模块。

In linux you need to ON rewrite module.

打开终端(ctrl + alt + t)并运行此命令。

open your terminal(ctrl+alt+t) and run this command.

sudo a2enmod rewrite

然后通过以下命令重新启动apache2:-

then restart apache2 by this command:-

sudo service apache2 restart

本教程链接将为您提供帮助。

This tutorial link will help you.

希望它对您有用:)

这篇关于删除文件扩展名时出现404错误,但在wamp上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆