无法在godaddy的.htaccess文件中隐藏php扩展名

时间:2015-09-28 09:10:25

标签: php mod-rewrite

您好,这是我的.htaccess文件的代码。我已经尝试了很多代码来隐藏代码,但没有id工作请帮助我..这是我的完整htaccess文件。这个隐藏代码我发现有点好,但这显示了我的页面内容。

     Options +FollowSymLinks -MultiViews 
     # Turn mod_rewrite on
     RewriteEngine On
     RewriteBase /

      ## hide .php extension
      # To externally redirect /dir/foo.php to /dir/foo
      RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
      RewriteRule ^ %1 [R,L,NC]

   ## To internally redirect /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^ %{REQUEST_URI}.php [L]


    ErrorDocument 404 http://www.mydomainname.com/
    Options +FollowSymLinks


     #Disable directory browsing       
     Options -Indexes

  RewriteEngine on

 #Redirect non-www to www   
 RewriteCond     %{HTTP_HOST}    ^mydomainname\.com$
 RewriteRule     (.*)    http://www.mydomainname.com/$1    [R=301,L]


RewriteRule pages/(.*) page.php?page=$1

RewriteRule blog/(.*) blog.php?type=$1

 RewriteRule post/(.*)/(.*) post.php?pid=$1&name=$2

 RewriteRule news-and-events/(.*)/(.*) news.php?nid=$1&name=$2 

   i found many code but none is working 

1 个答案:

答案 0 :(得分:0)

使用此.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]