隐藏带有htaccess变量的.php文件

隐藏带有htaccess变量的.php文件,php,.htaccess,mod-rewrite,redirect,hide,Php,.htaccess,Mod Rewrite,Redirect,Hide,我的htaccess文件有问题,我试图隐藏我网站上的所有.php扩展名, 我尝试了许多htaccess代码,但大多数代码都给了我错误,404未找到,我的大多数文件都包含诸如?id和?category、index/?cat=Action之类的变量,我希望htaccess隐藏php扩展名并将/dir/foo转发到/dir/foo.php,请帮助我:) 您可以在根目录中使用此代码。htaccess: RewriteEngine On RewriteBase / # To externally red

我的htaccess文件有问题,我试图隐藏我网站上的所有.php扩展名,
我尝试了许多htaccess代码,但大多数代码都给了我错误,404未找到,我的大多数文件都包含诸如?id和?category、index/?cat=Action之类的变量,我希望htaccess隐藏php扩展名并将/dir/foo转发到/dir/foo.php,请帮助我:)


您可以在根目录中使用此代码
。htaccess

RewriteEngine On
RewriteBase /

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

# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

您需要将php编写到URL的末尾,而不是相反。您可以这样编写变量:
href=“foo?bar=1”
。这段代码对我很有用:

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

这是错误的做法。您必须检测“no.php扩展名”URL,并将其重新写入.php文件。e、 g.“detect/foo/bar,重写为/foo/bar.php”我想更改?id=/idies,但您需要在客户端上有友好的URL。e、 g.用户浏览器应显示
/id
。然后你的重写将
RewriteRule^(\d+)whatever.php?id=$1
如果你开始向客户端发送“丑陋”的URL,那么所有这些都是毫无意义的。我想更改?id=/id你在问题中清楚地写了这个要求吗?如果你不能通过编辑你的问题来澄清所有这些案例,我将尝试回答它们。
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php