.htaccess RewriteRule不影响常规文件请求?

时间:2013-11-18 04:28:34

标签: php regex apache .htaccess mod-rewrite

我正在尝试为在Apache上运行的Web应用程序设置一个简短的URL服务。我对它的.htaccess部分感到难过,其中“http://shrt.url/username”和“http://longer.url/username”之类的请求应该总是调用我的forward.php文件。但我还需要规则忽略常规请求(如对图像和脚本的请求)。

当只有1 /&时,调用forward.php的RewriteRule是什么?没有.的样子?谢谢!

1 个答案:

答案 0 :(得分:1)

  

What does a RewriteRule which calls up forward.php ONLY when there's just 1 / & no .'s look like?

不太清楚你在寻找什么,但这个可能适合你:

RewriteEngine On

# if not a file    
RewriteCond %{REQUEST_FILENAME} !-f
# if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
# URI has one / and no dots then forward to /forward.php internally
RewriteRule ^([^/.]+)/?$ /forward.php?q=$1 [L]

参考:Apache mod_rewrite Introduction

相关问题