【问题标题】:.htaccess file not working for extension hiding.htaccess 文件不适用于扩展隐藏
【发布时间】:2014-04-03 12:51:08
【问题描述】:

我在.htaccess文件中使用下面的代码来隐藏php文件的扩展名。

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

我把这个文件放在localhost/obis/ 但是当我运行没有.php扩展名的index.php文件时,会出现以下错误。

The requested URL /obis/index was not found on this server.

谁能提出可能是什么错误?

我从本教程中获取了代码:http://www.youtube.com/watch?v=L6k_WvvpPpk

【问题讨论】:

  • 我已经检查过了,但它没有给我一个可行的解决方案。
  • ^ ([^\.]+)$ $1.php [NC]有空格,应该是^([^\.]+)$ $1.php [NC]
  • 不,它不工作!
  • 试试这个RewriteRule ^(.*)([^\.]+)$ $1$2.php [NC]

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

在 root .htaccess 中尝试以下两条规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index([/.]|$) /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

【讨论】:

  • 我收到此错误:在此服务器上找不到请求的 URL /obis/sign-up。
  • 当我们点击徽标返回主页时,有什么办法可以隐藏 url 中的“索引”?
  • 不,它不会删除index
  • 它实际上将 site.com/index.php 重定向到 site.com/ 对哪个 URL 不起作用?
猜你喜欢
  • 2013-02-03
  • 2014-03-29
  • 2017-01-29
  • 1970-01-01
  • 2017-10-06
  • 2017-09-24
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多