【问题标题】:.htaccess not working on localhost | lampp | Ubuntu.htaccess 在本地主机上不起作用 |灯 | Ubuntu
【发布时间】:2014-07-11 14:36:47
【问题描述】:

我正在尝试实现 url 重写以从 php 文件中删除 php 扩展名,但我不知道出了什么问题! 我在 ubuntu 机器上使用 Lampp,我什至在 httpd.conf 中将 AllowOverride 从 none 设置为 All:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All   <--- I set it from "None" to "All"

并且我已将我的 .htacces 文件放在我的项目文件夹的根目录中,即。项目/测试/(我什至不知道这是 .htaccess 文件的正确位置)。我的本地主机 url 就像:http://localhost/projects/test/abc.php。我希望将其设置为http://localhost/projects/test/abc。这是我的 url 重写代码:

Options +FollowSymLinks -MultiViews

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

我什至尝试过&lt;IfModule mod_rewrite.c&gt;

【问题讨论】:

  • I cannot figure out what's wrong! 你能想到什么?当你使用你的规则时会发生什么?你的 error_log 和 rewrite_log 向你展示了什么?是否在服务器 httpd.conf 上的 loadmodules 中启用了 mod_rewrite?
  • 抱歉我的无知,我是 .htaccess 的新手。正如我所说,我想从 abc.php 中删除 .php 扩展名。问题是浏览器仍然将 url 显示为localhost/projects/test/abc.php(应该是localhost/projects/test/abc)。再次抱歉,我不知道在哪里可以找到您提到的那些日志文件。
  • 使用当前规则,您将添加 .php 扩展而不是删除它。
  • 请先使用搜索引擎,因为这是一个使用 mod_rewrite 的简单任务,之前已经解决了几千次。
  • @feeela 我正在关注这里提到的教程:alexcican.com/post/…,并且我已经将代码与不同的 stackoverflow 答案相结合。你能写出删除 .php 扩展名的代码吗?

标签: php .htaccess mod-rewrite ubuntu lampp


【解决方案1】:

只是猜测,我会检查您需要的 Apache 模块是否已启用。 mod_rewrite

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

【讨论】:

  • 使用 phpinfo(); 'mod_rewrite' 在 apache2configuration 的“加载的模块”部分中提到。
  • 我的错,对不起,你已经提到了。我要解决的问题是通过您自己尚未配置的第三方将站点和 htaccess 上传到托管服务器,看看它是 htaccess 问题还是 apache 配置问题
猜你喜欢
  • 2016-12-30
  • 1970-01-01
  • 2012-08-17
  • 2012-05-03
  • 2021-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多