使用htaccess删除网站的php扩展

使用htaccess删除网站的php扩展,php,apache,.htaccess,Php,Apache,.htaccess,我的网站上有以下链接: 我只能在我的问题中添加2个URL,因为我是n00b 我在htaccess中添加了一个代码,这样我就可以在不使用php的情况下访问这些页面: 它适用于以下代码: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] 但我在php文件中使用了某些表单: <form name="planning" enctype="multipart/form

我的网站上有以下链接:

我只能在我的问题中添加2个URL,因为我是n00b

我在htaccess中添加了一个代码,这样我就可以在不使用php的情况下访问这些页面:

它适用于以下代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
但我在php文件中使用了某些表单:

<form name="planning" enctype="multipart/form-data" method="post" action="email/index.php">
我在htaccess中发送带有添加代码的表单时出错:

没有找到。 在此服务器上找不到请求的URL/email/

有人知道如何修改这个代码吗?我一直在搜索和测试,但似乎无法解决这个问题

非常感谢


Tomas

也添加此代码,它将允许您访问目录

RewriteCond %{REQUEST_FILENAME} !-d

另外添加此代码,它将允许您访问目录

RewriteCond %{REQUEST_FILENAME} !-d
试试这个规则:-

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
以下是规则工作原理的基本说明:-

正则表达式

使用正则表达式,可以搜索URL中的各种模式,并在它们匹配时重写它们

旗帜

将标志添加到重写规则的末尾,以告知Apache如何解释和处理该规则。它们可以用来告诉apache将规则视为不区分大小写,如果当前规则匹配,则停止处理规则,或者其他各种选项。它们以逗号分隔,并包含在方括号中。这是一张旗帜的列表,以及它们的含义

C (chained with next rule)
CO=cookie (set specified cookie)
E=var:value (set environment variable var to value)
F (forbidden - sends a 403 header to the user)
G (gone - no longer exists)
H=handler (set handler)
L (last - stop processing rules)
N (next - continue processing rules)
NC (case insensitive)
NE (do not escape special URL characters in output)
NS (ignore this rule if the request is a subrequest)
P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
R (temporary redirect to new URL)
R=301 (permanent redirect to new URL)
QSA (append query string from request to substituted URL)
S=x (skip next x rules)
T=mime-type (force specified mime type)
例外和特殊情况

重写条件可以通过几种不同的方式进行测试——它们不需要被视为正则表达式模式,尽管这是它们最常用的使用方式。以下是处理重写条件的各种方法:

<Pattern (is test string lower than pattern)
>Pattern (is test string greater than pattern)
=Pattern (is test string equal to pattern)
-d (is test string a valid directory)
-f (is test string a valid file)
-s (is test string a valid file with size greater than zero)
-l (is test string a symbolic link)
-F (is test string a valid file, and accessible (via subrequest))
-U (is test string a valid URL, and accessible (via subrequest))
希望它能帮助您:

试试这个规则:-

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
以下是规则工作原理的基本说明:-

正则表达式

使用正则表达式,可以搜索URL中的各种模式,并在它们匹配时重写它们

旗帜

将标志添加到重写规则的末尾,以告知Apache如何解释和处理该规则。它们可以用来告诉apache将规则视为不区分大小写,如果当前规则匹配,则停止处理规则,或者其他各种选项。它们以逗号分隔,并包含在方括号中。这是一张旗帜的列表,以及它们的含义

C (chained with next rule)
CO=cookie (set specified cookie)
E=var:value (set environment variable var to value)
F (forbidden - sends a 403 header to the user)
G (gone - no longer exists)
H=handler (set handler)
L (last - stop processing rules)
N (next - continue processing rules)
NC (case insensitive)
NE (do not escape special URL characters in output)
NS (ignore this rule if the request is a subrequest)
P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
R (temporary redirect to new URL)
R=301 (permanent redirect to new URL)
QSA (append query string from request to substituted URL)
S=x (skip next x rules)
T=mime-type (force specified mime type)
例外和特殊情况

重写条件可以通过几种不同的方式进行测试——它们不需要被视为正则表达式模式,尽管这是它们最常用的使用方式。以下是处理重写条件的各种方法:

<Pattern (is test string lower than pattern)
>Pattern (is test string greater than pattern)
=Pattern (is test string equal to pattern)
-d (is test string a valid directory)
-f (is test string a valid file)
-s (is test string a valid file with size greater than zero)
-l (is test string a symbolic link)
-F (is test string a valid file, and accessible (via subrequest))
-U (is test string a valid URL, and accessible (via subrequest))

希望它能对您有所帮助:

您好,它已经与Gorkem的更改建议一起工作了。还是你的代码更好?RewriteCond%{REQUEST_FILENAME}上的RewriteEngine-f RewriteCond%{REQUEST_FILENAME}-重写规则^[^\.]+$$1.php[NC,L][NC,L]-告诉Apache如何应用规则的标志。在本例中,我们使用两个标志。NC,告诉Apache这个规则应该不区分大小写,L告诉Apache如果使用这个规则,不要再处理任何规则。请检查我更新的答案。它将帮助您了解规则是如何运作的:嗨,它已经与Gorkem的变更建议一起工作了。还是你的代码更好?RewriteCond%{REQUEST_FILENAME}上的RewriteEngine-f RewriteCond%{REQUEST_FILENAME}-重写规则^[^\.]+$$1.php[NC,L][NC,L]-告诉Apache如何应用规则的标志。在本例中,我们使用两个标志。NC,告诉Apache这个规则应该不区分大小写,L告诉Apache如果使用这个规则,不要再处理任何规则。请检查我更新的答案。它将帮助您了解规则是如何运作的: