Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从URL(如.php或.html)中删除文件扩展名_Php_Html_Apache_.htaccess_Server - Fatal编程技术网

从URL(如.php或.html)中删除文件扩展名

从URL(如.php或.html)中删除文件扩展名,php,html,apache,.htaccess,server,Php,Html,Apache,.htaccess,Server,我想从我网站的URL中删除我的任何文件扩展名 例如:www.example.ml/dash/logins/sign.php 致:www.example/dash/logins/sign/ 我用谷歌搜索了很多次,但没有一个答案对我有用。 我认为它不起作用,因为在logins文件夹中我没有一个文件 还有许多其他文件,如index.php、sign.php等。我是否必须将每个文件保存在单独的文件夹中,或者sing.php可以更改为sign/。此外,这会发生什么情况: sign.php?usercode

我想从我网站的URL中删除我的任何文件扩展名

例如:www.example.ml/dash/logins/sign.php
致:www.example/dash/logins/sign/

我用谷歌搜索了很多次,但没有一个答案对我有用。 我认为它不起作用,因为在logins文件夹中我没有一个文件

还有许多其他文件,如index.php、sign.php等。我是否必须将每个文件保存在单独的文件夹中,或者sing.php可以更改为sign/。此外,这会发生什么情况:

sign.php?usercode=1
它会被转换成

sign/usercode=1
?

我已经有一些代码存在于.htaccess中,所以请在参考此代码后给出您的答案

php_value display_errors Off
php_flag magic_quotes 1
php_flag magic_quotes_gpc 1
php_value mbstring.http_input auto
php_value date.timezone America/New_York

Options -Indexes

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.example.ml$ [NC]

RewriteRule ^(.*)$ https://www.example.ml/$1 [L,R=301]

将此行添加到.htaccess文件:

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

在.htaccess文件中使用此代码。它会将PHP文件重定向到非PHP版本

# Turn on the rewrite engine
RewriteEngine  on
# If the request doesn't end in .php (case insensitive) continue processing rules
RewriteCond %{REQUEST_URI} !\.php$ [NC]
# If the request doesn't end in a slash continue processing the rules
RewriteCond %{REQUEST_URI} [^/]$
# Rewrite the request with a .php extension. L means this is the 'Last' rule
RewriteRule ^(.*)$ $1.php [L]
这个例子来自Tim Bielwa,

谢谢,它成功了,但在键入extension之后,它也打开了,我想强制每个url删除它的扩展。htaccess不能限制这一点。它只是重写你的url。要做到这一点,您必须创建一个中间页面,其中uri将充当get参数,页面将基于此显示。这样做会花费更多的成本。