繁体   English   中英

用htaccess删除网站的php扩展名

[英]Remove php extension of website with htaccess

我的网站上有这些链接:

http://crw4u.be/werkgever.php (由于我是n00b,我只能在问题中添加2个网址)

我向htaccess添加了代码,因此无需php就可以访问这些页面:

http://crw4u.be/werkgever

此代码可以正常工作:

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 /。

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

高度赞赏!

托马斯

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

RewriteCond %{REQUEST_FILENAME} !-d

尝试以下规则:

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

这是规则运作方式的基本说明:

常用表达

. (any character)
* (zero of more of the preceding)
+ (one or more of the preceding)
{} (minimum to maximum quantifier)
? (ungreedy modifier)
! (at start of string means "negative pattern")
^ (start of string, or "negative" if at the start of a range)
$ (end of string)
[] (match any of contents)
- (range if used between square brackets)
() (group, backreferenced group)
| (alternative, or)
\ (the escape character itself)

使用正则表达式,可以搜索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))

希望它能对您有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM