【问题标题】:My htaccess doesn’t remove extension .php我的 htaccess 没有删除扩展名 .php
【发布时间】:2014-08-01 10:38:09
【问题描述】:

我在一个名为 env_files 的文件夹中定义了三个 htaccess,并且我还有其他 .htaccess 内部公共文件:

所有htaccess代码都是正确的:

# development
DirectoryIndex index.php
#Options -Indexes
ErrorDocument 404 error404
ErrorDocument 500 error404

RewriteEngine On

# REDIRECTS FROM WWW TO NON www URL
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# AVOID URL END DOT (COOKIE PROBLEMS) mydomayin.com. 
RewriteCond %{HTTP_HOST} (.*)\.$
RewriteRule (.*) http://%1/$1 [L,R=301]

# REMOVE EXTENSION .PHP
RewriteCond %{REQUEST_FILENAME} !\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_headers.c>
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf|woff|eot|svg|ttf|flv|swf)$">
  Header set Cache-Control "public, max-age=29030400"
</FilesMatch>
</IfModule>

    ## Desactiva la firma del servidor ##
ServerSignature Off

但我的网站无法加载没有 .php 扩展名的 pages.php: http://calendario-online.es/calendario-laboral-2015-cordoba

如果您在 URL 的末尾写上“.php”,则页面加载。

为什么会这样?

【问题讨论】:

  • 您有一组RewriteConds,但如果满足条件,则没有RewriteRule

标签: php


【解决方案1】:

试试这个:

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

【讨论】:

    【解决方案2】:
     Try with this:
    
     RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    

    【讨论】:

      【解决方案3】:

      下面的 .htaccess 代码可以帮助您解决问题

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-30
        • 1970-01-01
        • 1970-01-01
        • 2014-12-22
        相关资源
        最近更新 更多