.htaccess不适用于UMLAUT和(后)URI

.htaccess不适用于UMLAUT和(后)URI,.htaccess,.htaccess,我需要您对我的.htaccess文件的帮助(这些文件是我最喜欢的任务之一:-))。我当前的.htaccess看起来是这样的: # Start rewrite engine RewriteEngine on # Check if no file, link or directory is requested RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-s RewriteCond %{REQUEST_

我需要您对我的.htaccess文件的帮助(这些文件是我最喜欢的任务之一:-))。我当前的.htaccess看起来是这样的:

# Start rewrite engine
RewriteEngine on 

# Check if no file, link or directory is requested
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-d

# Do not rewrite install and admin
RewriteRule ^admin$ admin/ [R=301,L]
RewriteRule ^install$ install/ [R=301,L]

# Pass the requested path to index.php
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$ index.php?p=$1/$2 [QSA]
RewriteRule ^([a-zA-Z0-9_]+)$ index.php?p=$1 [QSA]

# Define error document for all errors
ErrorDocument 401 index.php?p=error
ErrorDocument 403 index.php?p=error
ErrorDocument 404 index.php?p=error
ErrorDocument 410 index.php?p=error
主要功能正常工作,但我有以下问题:


如果生成错误(例如访问
/unknownFolder
),则会根据需要加载错误页面。但是如果我的URI中有umlauts(特别是ä,ü,ö,ß),那么只有输出
index.php?p=error
。对这个可笑的问题有什么解释或解决方法吗?

您的正则表达式与以下字符不匹配:
([a-zA-Z0-9_239;]+)
。尝试将这些分组更改为
([^/]+)
,以便匹配除斜线和点之外的所有内容:

# Pass the requested path to index.php
RewriteRule ^([^/.]+)/([^/.]+)$ index.php?p=$1/$2 [QSA]
RewriteRule ^([^/.]+)$ index.php?p=$1 [QSA]

可能发生的情况是,这些umlat字符没有与这些规则匹配,它们没有正确地路由到
index.php
文件,因此404。

谢谢你的回答,现在就可以了:-)但我不明白,重写规则与ErrorDocuments有什么关系。如果你能进一步解释这一点就好了,但这不是必要的。还有一种解决方案可以使ErrorDocuments相对于.htaccess的路径,比如.htaccess的
dirname(\uu文件\uu)
。请求通过一个模块管道进行处理,直到最后映射到一个资源(如文件系统中的文件)。将请求路由到
index.php
RewriteRule
实际上更改了URI,因此当该请求最终到达管道末端时,URI是
/index.php?p=umlats
或其他任何内容。由于
index.php
存在,它将被映射并运行脚本。但是,如果该规则不匹配,umlat URI将一直执行到管道的末尾,并且由于这不是一个资源,它将感谢您的解释。您是否有一种方法可以使ErrorDocument相对于.htaccess?@RichardReiber您可能需要检测到,
ErrorDocument
指令需要一个绝对URL,因此无法使其相对于某个目录。因此,在php脚本中,可以通过服务器变量进行检测。方括号中的“^”表示“除以下内容之外的任何内容”。所以
[^/]
表示除斜杠和句点以外的任何内容,而
[^.]
表示除句点以外的任何内容