什么是htaccess中的符号,它的作用是什么

时间:2013-02-11 00:18:27

标签: .htaccess

|符号在htaccess中的作用是什么。我从htaccess的在线论坛中获取了一个代码,他们使用了|。我想了解这个符号在htaccess中的含义是否存在任何差异,可能是管道符号|

RewriteEngine on
#
### Disallow Image Hotlinking
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://www\.example\.net
RewriteRule \.(jpe?g¦gif¦bmp¦png)$ - [F]
#
### Externally redirect to remove ".php" if the user adds it
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.example.net/$1 [R=301,L]
#
### Externally redirect to remove double slashes
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . http://www.example.net/%1/%2 [R=301,L]
#
### Externally redirect to remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://www.example.net/$1 [R=301,L]
#
### Externally redirect non-canonical hostname requests to canonical
### domain (if not already done by one of the preceding rules)
RewriteCond %{HTTP_HOST} !=www.example.net
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]
#
### Internally rewrite requests for URLs which do not resolve
### to physically-existing files or directories to a PHP file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

1 个答案:

答案 0 :(得分:1)

当然不应该在那里,并且可能是因为从包含错误符号的来源复制和粘贴而到达那里。

对于RegExp库,它只是另一个没有任何特殊含义的文字字符。它不会被视为管道符号,即它类似于写作

RewriteRule \.(jpe?gxgifxbmpxpng)$ - [F]

它会使规则变得毫无用处。

来源:经过测试以确保。