【问题标题】:Apache .htaccess to hide both .php and .html extentionsApache .htaccess 隐藏 .php 和 .html 扩展名
【发布时间】:2013-03-13 13:03:08
【问题描述】:

我应该添加哪些行来从我的站点中同时删除 .html.php 扩展名?

我只将它用于.html 部分:

RewriteEngine on

RewriteBase /
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L]

但我需要对同一个域隐藏两个文件类型扩展名。

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting rewrite


    【解决方案1】:

    我知道回答晚了,但我给了它,因为它可能对某人有用:)

    #Remove php extension
        RewriteEngine on 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteCond %{REQUEST_FILENAME}\.php -f 
        RewriteRule ^(.*)$ $1.php
    
    #Remove html extension
        RewriteEngine on 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteCond %{REQUEST_FILENAME}\.html -f 
        RewriteRule ^(.*)$ $1.html
    

    这将从您的文件中删除 php 和 html 扩展名并完美运行。

    【讨论】:

      【解决方案2】:

      您可能想测试带有.html.php 的文件是否存在,如果存在则重定向到该文件。

      RewriteEngine on
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME}.html -f
      RewriteRule ^(.*)$  $1.html [L]
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME}.php -f
      RewriteRule ^(.*)$  $1.php [L]
      
      RewriteCond %{REQUEST_URI} \.((html)|(php))$
      RewriteRule ^(.*)\.([^.]+)$  $1 [R,L]
      

      【讨论】:

      • @Blazer,嘿,既然一切正常,您有机会点击接受答案吗? :-)
      • @Blazer,既然这工作得很好,你有没有机会点击接受按钮,这样你和我都得到了努力工作的积分?谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 1970-01-01
      • 2017-09-24
      • 2012-04-19
      • 2010-12-31
      • 2012-03-06
      相关资源
      最近更新 更多