【问题标题】:How to hide php extension in url? [duplicate]如何在url中隐藏php扩展? [复制]
【发布时间】:2014-02-21 05:46:09
【问题描述】:

我在 Windows 7 中使用“xampp”。 我的 index.php 在 localhost(root) 下的文件夹中,路径类似于 (http://localhost/folder/index.php) 我在文件夹下的“.htaccess”文件中添加了以下几行

RewriteEngine On
RewriteRule index index.php [L]

但它不起作用。 帮帮我。

【问题讨论】:

  • @Rikesh 我试过它不工作
  • 确保你的服务器上有mod_rewrite
  • @Rikesh 是的,它可用
  • 确保 allowoverride 设置为 ALL

标签: php .htaccess xampp


【解决方案1】:

试试这个

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php

也启用重写模块

【讨论】:

【解决方案2】:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php?%{QUERY_STRING}

【讨论】:

  • 不工作,在哪里放置'.htaccess'文件?
  • @sufi,它可以工作,启用 mod_rewrite
【解决方案3】:

试试

重写引擎开启 RewriteRule ^index$ index.php [NC,L]

【讨论】:

  • 不工作,在哪里放置'.htaccess'文件?
  • 'RewriteEngine On RewriteRule index.php index [L]' 这在link 中工作正常,但在浏览器中不工作。
猜你喜欢
  • 1970-01-01
  • 2021-01-23
  • 2011-09-08
  • 2014-03-23
  • 2012-01-12
  • 2012-04-19
  • 2018-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多