htaccess RewriteRule问题 [英] htaccess RewriteRule problem

查看:93
本文介绍了htaccess RewriteRule问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对RewriteRules有问题.

I have a problem with RewriteRules.

我当前正在使用此规则:

I'm currently using this rule:

RewriteRule ^([^/.]+)/?$ index.php?clip=$1

对于这样的链接来说,这很好用,其中$_GET['clip']是斜杠后的值:

This works fine for links as these, where $_GET['clip'] is the value after the slash:

http://example.com/abcdefg

但不适用于像这样的点字符的人:

But not for those with a dot character, like these:

http://example.com/abcdefg.png

如何更改RewriteRule以使其适用于此类链接?

How should I change the RewriteRule to make it work for such links?

推荐答案

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?clip=$1

我不建议使用此技术,因为它将导致额外的磁盘读取,以检查文件是否存在... 如果您有可能,我建议您以apache可以从目录中告诉您要做什么的方式来组织您的目录结构.我的框架中的示例:

i wouldn't suggest this technique because it will cause an extra disk read to check if the file is there... if you have the possibility i would advise to organize your directory structure in a way that apache can tell from the directory what to do. example from my framework:

  # skip whitelisted directories
  RewriteRule ^(test|skin|stylesheets|images|javascripts|favicon|robots\.txt|index\.php) - [L]
  RewriteRule ([-_\w\/]*) index.php?p=$1 [NE,NC,QSA]

这篇关于htaccess RewriteRule问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆