当我在 RegExr ( http://regexr.com?36ms0 )中测试它时,我有这个正则表达式可以完美运行,但是当我将它添加到我的 .htaccess 时它永远不会匹配。
正则表达式:
^(?!.*\.(?:(?:ht|x)ml|j(?:peg|s|pg)|p(?:hp|ng)|[rc]ss|bmp|ico|gif)$).*$
此正则表达式应匹配“testphp”和“test.rar”等字符串,但不匹配“test.php”或任何其他包含的扩展名。
.htaccess 在子域中
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# handle YouTube token
RewriteCond %{QUERY_STRING} ^token=(.*)$
RewriteRule ^login/ login/%1/? [NE,R=301,L]
# add trailing slash for the looks
RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]
# html5 pushstate (history) support:
# we do want to give error pages for certain file types though.
RewriteCond %{REQUEST_FILENAME} ^(?!.*?\.((ht|x)ml|j(peg|s|pg)|p(hp|ng)|[rc]ss|bmp|ico|gif)$).*?$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) / [L]
</ifModule>
此 .htaccess 文件的目的是将任何请求重定向到索引,除了任何以 .php、.html、.css、jpg、... 结尾的文件以及任何存在的文件或目录。浏览到http://mysite.com/test/
将重定向到索引。浏览到http://mysite.com/test.php
将显示该文件或 404(如果它不存在)。浏览到http://mysite.com/test.rar
将下载文件或重定向到索引(如果它不存在)。
我的服务器根目录中有另一个 .htaccess:
SetEnv PHPRC /home/ttrcusto/public_html/cgi-bin/php.ini
<Files ~ "\.(ini)$">
order allow,deny
deny from all
</Files>
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
Redirect /unsubscribe http://ttrcustoms.us/#account=edit
Redirect /cydia http://repo.ttrcustoms.us
Redirect /Cydia http://repo.ttrcustoms.us
Redirect /repo http://repo.ttrcustoms.us
Redirect /tools http://tools.ttrcustoms.us
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^repo/deb/(.*)\.deb$ /download.php?package=$1.deb [L,QSA]