简体   繁体   English

用htaccess删除网站的php扩展名

[英]Remove php extension of website with htaccess

I have these links on my website: 我的网站上有这些链接:

http://crw4u.be/werkgever.php (I can only add 2 urls in my question, since i'm a n00b) http://crw4u.be/werkgever.php (由于我是n00b,我只能在问题中添加2个网址)

I added a code to htaccess so I can access these pages without the php: 我向htaccess添加了代码,因此无需php就可以访问这些页面:

http://crw4u.be/werkgever http://crw4u.be/werkgever

It works fine with this code: 此代码可以正常工作:

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

Yet I use certain forms in my php files: 但是我在php文件中使用了某些形式:

<form name="planning" enctype="multipart/form-data" method="post" action="email/index.php">

And I'm getting errors when sending the form with the added code in htaccess: 而且在发送带有htaccess中添加的代码的表单时出现错误:

Not Found . 未找到 The requested URL /email/ was not found on this server. 在此服务器上找不到请求的URL / email /。

Does anyone knows how to adapt this code? 有谁知道如何修改此代码? I've been searching and testing, but can't seem to solve this. 我一直在搜索和测试,但似乎无法解决此问题。

Highly appreciated! 高度赞赏!

Tomas 托马斯

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

RewriteCond %{REQUEST_FILENAME} !-d

Try this Rule:- 尝试以下规则:

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

Here is basic description for how rules are working:- 这是规则运作方式的基本说明:

Regular Expressions 常用表达

. (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)

Using regular expressions, it is possible to search for all sorts of patterns in URLs and rewrite them when they match 使用正则表达式,可以搜索URL中的各种模式,并在它们匹配时重写它们

Flags 标志

Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. 将标志添加到重写规则的末尾,以告诉Apache如何解释和处理规则。 They can be used to tell apache to treat the rule as case-insensitive, to stop processing rules if the current one matches, or a variety of other options. 它们可用于告诉apache将规则视为不区分大小写,如果当前规则匹配则停止处理规则,或使用其他多种选择。 They are comma-separated, and contained in square brackets. 它们用逗号分隔,并包含在方括号中。 Here's a list of the flags, with their meanings. 这是标志的列表及其含义。

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)

Exceptions and Special Cases 例外和特殊情况

Rewrite conditions can be tested in a few different ways - they do not need to be treated as regular expression patterns, although this is the most common way they are used. 重写条件可以通过几种不同的方式进行测试-尽管这是使用它们的最常用方法,但不必将它们视为正则表达式模式。 Here are the various ways rewrite conditons can be processed: 以下是可以处理重写条件的各种方式:

<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))

Hope it will help you :) 希望它能对您有所帮助:)

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

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