问题描述
我刚刚完成安装在Ubuntu 12 LAMP堆栈,以及所遇到的问题与Apache的.htaccess文件。我重写并启用重定向器官功能障碍综合征,以及.htaccess文件是工作(该URI将重定向到WWW如果没有'WWW'present),但无论我怎么努力,我不能让它删除文件扩展名。我已经试过了<文件>
指令,没有运气。我现在的文件包括以下内容:
I just finished installing a LAMP stack on Ubuntu 12, and have run into an issue with Apache's .htaccess file. I have the rewrite and redirect mods enabled, and the .htaccess file is working (the URI will redirect to 'www' if there is no 'www' present), but no matter what I try, I cannot get it to remove file extensions. I've tried the <Files>
directive with no luck. My current file consists of the following:
RewriteEngine On
# Remove file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ $1.php [L]
# Force www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
在如何解决这一问题非常恼人的问题有什么建议?
Any suggestions on how to fix this very annoying problem?
推荐答案
您不要使用htaccess的做到这一点,你用你的应用程序来删除扩展和htaccess的映射扩展名的URL来真正的文件。这条规则
You don't use htaccess to do this, you use your app to remove the extensions, and htaccess to map extension-less urls to real files. This rule
# Remove file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
说:如果请求的资源不存在的文件,查找具有的.php
扩展的资源。所以,你删除的扩展名从你的应用程序的所有环节,这条规则将使得PHP文件运行不带扩展名。你htaccess是细如-是,你需要更新你的应用程序。
Says, "if the requested resource doesn't exist as a file, look for the resource with a .php
extension". So you remove the extension from all links in your app, and this rule will make the php file run without the extension. Your htaccess is fine as-is, you need to update your app.
这篇关于使用的.htaccess删除PHP文件扩展名的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!