在admin文件夹中的htasess文件中,删除了wamp上的php扩展名,尽管效果良好。当移动到带有lamp服务器的ubuntu时。它给出的404没有找到。但是htaccess完全适用于索引路由之类的其他事情。下面是我在htaccess文件上使用的内容。
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
或
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
或
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^'.]+)$ $1.php [NC,L]
如果这个全局规则不适用于你,那么也可以尝试下面的代码:-
在这段代码中,将'work'
替换为您的项目根目录。
RewriteEngine on
RewriteBase /work/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !'.php$
RewriteRule .* $0.php [L]
在linux中,您需要打开重写模块。
打开终端(ctrl+alt+t)并运行此命令。
sudo a2enmod rewrite
然后通过以下命令重新启动apache2:-
sudo service apache2 restart
此教程链接将对您有所帮助。
希望它能为您工作:)