本文介绍了重写规则htaccess的,以匹配特定的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我如何查找某些文件扩展名的实例,等等。(JPG | PNG | CSS | JS | PHP),如果有不匹配发送到index.php路线= $ 1我希望能够让时间的自定义的用户名。所以,重写 http://example.com/my.name 的index.php?路径= my.name当前设置:的.htaccess: &LT; IfModule mod_rewrite.c&GT;RewriteEngine叙述上的RewriteBase /的RewriteCond%{} REQUEST_FILENAME!-f的RewriteCond%{} REQUEST_FILENAME!-d重写规则^([^。] +)$的index.php?路径= $ 1 [QSA,L]&LT; / IfModule&GT;什么工作: http://example.com/userpage ? - >的index.php路线= userpage http://example.com/userpage/photos ? - >的index.php路线= userpage /照片 http://example.com/file.js - >的 http://example.com/file.js http://example.com/css/file.css - >的 http://example.com/css/file.css我需要的除了工作上面: http://example.com/my.name ? - >的index.php路线= my.name解决方案 添加一个额外的RewriteCond排除不希望改写的条件。使用!前的常规EX pression指示的任何文件匹配出现故障的情况。以下的RewriteCond是未经测试,但应该给你什么,你需要一个想法: 的RewriteCond%{REQUEST_URI} \(JPG | PNG | CSS | JS | PHP)!$。 How can I look for an instance for certain file extensions, like .(jpg|png|css|js|php), and if there is NOT a match send it to index.php?route=$1.I would like to be able to allow period's for custom usernames.So, rewrite http://example.com/my.name to index.php?route=my.nameCurrent setup:.htaccess:<IfModule mod_rewrite.c>RewriteEngine onRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^.]+)$ index.php?route=$1 [QSA,L]</IfModule>What works:http://example.com/userpage -> index.php?route=userpagehttp://example.com/userpage/photos -> index.php?route=userpage/photoshttp://example.com/file.js -> http://example.com/file.jshttp://example.com/css/file.css -> http://example.com/css/file.cssWhat I need to work in addition to above:http://example.com/my.name -> index.php?route=my.name 解决方案 Add an extra RewriteCond to exclude the conditions that you don't want rewritten. Use a ! before the regular expression to indicate that any files matching should fail the condition. The RewriteCond below is untested, but should give you an idea of what you need:RewriteCond %{REQUEST_URI} !\.(jpg|png|css|js|php)$ 这篇关于重写规则htaccess的,以匹配特定的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-24 11:22